P
P
PesyCorm2021-01-31 00:42:23
Python
PesyCorm, 2021-01-31 00:42:23

How to wait for webelement clickability (selenium+python)?

Hey! Tell me, is there a way to wait for the clickability of an existing web element?
That is, I already got it from find_elements_by_*, but when I call the method click()I get an error

Message: stale element reference: element is not attached to the page document

If used time.sleep()before clicking on an element, then everything works correctly. How can I make an element clickable wait? Thanks for the answer!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wispik, 2021-01-31
@Wispik

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "тут xpath"))).click()

example with xpath, naturally by class and id you can also search

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question