I'm writing a script to download a set of files on a website using Selenium and its Chrome driver in Python, but I find it disgusting to see the browser opens and gets a focus whenever the program opens a new tab or clicks on the download button.
So I rather want to use headless mode. But then, the element always gets me the following error:
WebDriverException: Message: unknown error: Element ... is not clickable at point (435, 575). Other element would receive the click:
...
(Session info: headless chrome=66.0.3359.139) (Driver info: chromedriver=2.37.544337 (8c0344a12e552148c185f7d5117db1f28d6c9e85),platform=Mac OS X 10.13.4 x86_64)
This error once happened in my non-headless mode, but since I changed the size of the browser by driver.maximize_window()
, the error had gone out. This may make it clear the button must be visible on the screen, in order for it to be pushed on Chrome.
But in the headless mode, it might be true that the button is hidden and that's way the element is always unclickable, leading to the error. So it there any way to make the button clickable even on the headless mode?
The relevant code is the following, and the last line causes the error:
def login(driver, url, username, password):
driver.get(url)
uname = driver.find_element_by_name("login")
uname.send_keys(username)
passw = driver.find_element_by_name("password")
passw.send_keys(password)
submit_button = driver.find_element_by_class_name("button")
action = webdriver.ActionChains(driver)
action.move_to_element(submit_button)
submit_button.click()