Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

Python - Selenium - implicit wait for several elements

$
0
0

Currently I use implicit wait to locate elements before issuing any action upon them. See example of implicit wait:

WebDriverWait(browser,10).until(EC.presence_of_element_located(By.XPATH(('xpath')))

This works fine when dealing with a single element. However, it appears that if the xpath relates to multiple elements then EC.presence_of_element_located() will time out. My question is, how do I do an implicit wait for multiple elements?

Clarification:

Single element -

WebDriverWait(browser,10).until(EC.presence_of_element_located(By.XPATH(('xpath'))) browser.find_element_by_xpath('xpath')

Multiple element -

?? browser.find_elements_by_xpath('xpath')

Note: Notice use of find_elements_by_xpath() in multiple element instance instead of find_elements_by_xpath()

The problem here is that it is simpler for a single item. It just has to wait until your locator returns a single, or more, elements.

When you deal with multiple elements, WebDriver cannot possibly know how long to wait because it has no idea about how many elements you expect to be there.

So you'll have to use an explicit wait instead.

In this explicit wait, you should:

find_elements_by_path

http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp


Viewing all articles
Browse latest Browse all 9596

Trending Articles