Issue
I have something like this
el = WebDriverWait(browser, 10).until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, "till-cap"))
)
The problem with the above code is that it does not wait for all the element, it returns 5 instead of 12 elements, sometimes the elements could be more or less, I resolved this by using time.sleep(15)
in python, to wait for 15 seconds. But I feel this is not the best way to resolve this. Thank you.
Solution
Although this functionality is not a native function in Selenium, you can implement a lambda function to verify how many elements are present before moving on:
WebDriverWait(browser,10).until(lambda method: len(EC.presence_of_all_elements_located(By.CSS_SELECTOR, "till-cap")) == 12)
Java has Selenium-native functionality for this exact use case, but in Python we must improvise with the lambda method. To avoid a lambda, you could place your time.sleep() after the WebDriverWait function, as the rest of the elements often populate shortly after the first element:
el = WebDriverWait(browser, 10).until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, "till-cap"))
)
time.sleep(2)
This could allow you to decrease the time required in time.sleep(), but you will likely have to test a few times to see the minimum time required.
Answered By - samsupertaco
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.