Reputation: 1
Below code works fine in firefox without the sleep(1)
.
But in chrome, driver.find_element_by_xpath
fails.
If there is sleep(1)
in between, then it works.
//the wait below passes fine for both Chrome and Firefox.
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))
//In chrome this does not find the element.Works in firefox.
driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()
In chrome shows a
ElementNotVisibleException: Message: Message: element not visible
Below code works in both Chrome and Firefox
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))
sleep (1)
driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()
Upvotes: 0
Views: 2705
Reputation: 2148
You cannot click on an element that is not yet visible, use expected condition visibility_of_element_located instead:
// Wait until element is visible
WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))
driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()
Or better yet, since you're trying to click on it, you can also wait until element is clickable:
// Wait until element is clickable
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))
driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()
See Expected Conditions for more built convenience methods you can use to check for element states.
Upvotes: 2