Skip to content

Instantly share code, notes, and snippets.

@romain130492
Last active April 7, 2020 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romain130492/5df2c82770cc5845441017bb13299873 to your computer and use it in GitHub Desktop.
Save romain130492/5df2c82770cc5845441017bb13299873 to your computer and use it in GitHub Desktop.
#Selenium #Python #Scraping - wait

Scraping with Selenium/ Python

Wait to get an element on the page

    driver = webdriver.Firefox(firefox_options=options,
                               executable_path=geckodriver)

    driver.get(url)
    try:
        element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, ".tab-container")))
        a = []
        a = driver.find_elements_by_class_name("flex")
        for x in a:
            print(x.text, 'text of the element')
    finally:
        driver.quit()

Or Wait a certian amount of time

        driver = webdriver.Firefox()
        driver.implicitly_wait(30)  # seconds
        driver.get(url)
        a = []
        a = driver.find_elements_by_class_name("app-content-score")
        print(len(a), 'the len of A')
        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment