0

I have an unordered list after a button click and I want to get the number of how many uls are with paginated class.

 <ul class="paginated">  </ul>

Here is my code:

 element = driver.find_elements_by_class_name('paginated')
 print(len(element))

Sometimes I get 0 but there is one ul with class = paginated. I used time.sleep(1) and it's working perfectly. But I want to make it more dynamical. Can someone help me with a WebDriverWait line code to replace that time.sleep?

Paul Vio
  • 57
  • 1
  • 7
  • Does this answer your question? [Wait until page is loaded with Selenium WebDriver for Python](https://stackoverflow.com/questions/26566799/wait-until-page-is-loaded-with-selenium-webdriver-for-python) – Wonka Dec 30 '19 at 15:54
  • I am checking right now – Paul Vio Dec 30 '19 at 15:56

1 Answers1

1

Induce WebDriverWait() and element_to_be_clickable()

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'ul.paginated'))).click()

Import below libraries.

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

Edit:

print(len(WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, 'ul.paginated')))))
KunduK
  • 32,888
  • 5
  • 17
  • 41