简体   繁体   中英

headless mode python selenium, Timeoutexeption error

so I wanted to use headless mode in my python selenium project, and I get this error:

Exception has occurred: TimeoutException

The last traceback was on line 26, and it was also the first line after succesfully opening a website. Here is the line in question:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class=' css-1hy2vtq']"))).click()

What I've tried to solve it:

I've tried adding arguments to the chrome options, I've tried switching up the first line and so I found out that waiting for an element_to_be_clickable does not work but find_element(By , does (well in this case at least).

The classnames ie css-1hy2vtq , etc are dynamically generated and is bound to change sooner/later. They may change next time you access the application afresh or even while next application startup. So cann't be used in locators.


Solution

You need to consider any of the other attributes which is static in nature. Example:

//button[text()='Click Me']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM