问题
Let's say I'm selecting with the selector:
//img[@data-blabla]
And I want to wait for 10 elements to be loaded, not just one.
How would this be modified? I'm making a guess with the index [9]
WebDriverWait(browser, 5).until(EC.presence_of_element_located((By.XPATH, '//img[@data-blabla][9]')))
回答1:
To wait for 10 elements to load you can use the lambda
function and you can use either of the following Locator Strategies:
Using
>
:myLength = 9 WebDriverWait(browser, 20).until(lambda browser: len(browser.find_elements_by_xpath("//img[@data-blabla]")) > int(myLength))
Using
==
:myLength = 10 WebDriverWait(browser, 20).until(lambda browser: len(browser.find_elements_by_xpath("//img[@data-blabla]")) == int(myLength))
来源:https://stackoverflow.com/questions/64746509/how-to-wait-for-number-of-elements-to-be-loaded-using-selenium-and-python