I am scraping a website for data from a table, which is loaded via AJAX. The website is slow, and inconsistent, so sometimes I have to wait <5 sec for the table to load, while other times I have to wait 25 - 30. I am iterating through hundreds of items that filter the table, and once loaded, I go to the next item.
The functionality of the Explicit Wait / Expected Conditions does not seem to be behaving as I expect and wondered if anyone might have some insight.
I have tried numerous approaches to the problem, which I seem to have a different exception each time I run it.
This first snippet is to keep trying until it finds the element. I want to continue running until the page is fully loaded and the element is found. The problem is, the page is still loading and the element hasn't been found yet, but it still throws an exception.
for s in range(0,1000):
try:
#Other Month Value Clicked
wait.until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[9]/div/div[2]/div[" + str(mths[x]) + "]")))
except NoSuchElementException:
print(".", end=".", flush=True)
time.sleep(1)
timePeriodVal.click()
time.sleep(1)
timePeriodVal.click()
continue
finally:
timePeriod = (driver.find_element_by_xpath("/html/body/div[9]/div/div[2]/div[" + str(mths[x]) + "]"))
timePeriod.click()
#print('\nTime Period clicked')
time.sleep(1.5)
break