0

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()
2
  • seems that chrome takes up time to show up the element as compared to firefox. Commented May 31, 2016 at 5:57
  • Chrome actually does find the element, it's just not visible yet. Instead of wait until presence of element located, try using wait until visibility of element located. See Expected Conditions Commented May 31, 2016 at 6:36

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.