0

I'm designing a web scraper. At a few points I need it to wait for around 10 seconds before jumping to the next action to account for internet connection problems. I want to have a simple implicit wait.

driver.get('MY WEBSITE')

driver.implicitly_wait(10)

menu = driver.find_element_by_link_text("Export")
menu2 = driver.find_element_by_xpath('//td[text()="Data"]')

actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(menu)
actions.move_to_element(menu2)
actions.click(menu2)
actions.perform() 

The only problem is: it's not waiting. I've even tried putting 20 and more secs as the implicitly_wait parameter in order to be completely sure and there was no change. It's opening the website and going directly to search for the two elements. Can anyone explain that please?

2
  • How did you conclude it's not waiting? Complete error? Commented Jul 15, 2020 at 16:47
  • @DebanjanB, by observing it live. It opens the website and then clicks directly on the two menu elements specified. According to the implicitly_wait parameter it should wait 10 seconds. It doesn't. As I write, I even tried making it 30 seconds to be completely sure, but nothing changes. The page opens and then immediately after that the menu elements are clicked on. Commented Jul 15, 2020 at 16:50

2 Answers 2

4

From the docs:

An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find any element (or elements) not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object.

So if the element is immediately available, it won't wait.

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

1 Comment

Thanks. I thought it just checks once, after the specified number of seconds.
0

Try to use WebDriverWait :

E.g

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

driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )
finally:
    driver.quit()

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.