WebdriverWait is showing TimeoutException, if I use sleep.time it works ok
You are not using the Explicit Wait correctly - you need to make use of Expected Conditions - callables that would be called repeatedly until return True
. You are returning the result of click()
method which returns None
which is falsy - the expected condition never returns True
and, hence, you are getting TimeoutException
.
In this case, built-in element_to_be_clickable
fits nicely, example:
from selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Bywait = WebDriverWait(self.driver, 10)element = wait.until(EC.element_to_be_clickable((By.XPATH, '//div[@class="test"]')))element.click()
wait = WebDriverWait(driver, 10)paragraph = wait.until(EC.element_to_be_located((By.CSS_SELECTOR,"body > p:nth-child(3)")))paragraph.getText()