简体   繁体   中英

WebElement or WebDriver to invoke findElement method?

What is the difference if we invoke the findElement method using WebElement or WebDriver? Do each of them has advantage over the other? Thanks in advance.

The difference of findElement between WebElement and WebDriver is the context.

Whereas the context of WebDriver is the current page, the context of WebElement is that element. WebDriver will search across the whole document, while WebElement will try to find the first child element from that node.

Note that when searching with WebElement via XPath, starting with // will still search across the entire document, not just the children of the current node. You can use .// to limit the search results to the children of that WebElement .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM