Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.


1 Answers

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

Whereas the context of WebDriveris 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.

like image 148
Tom Verelst Avatar answered Nov 23 '25 20:11

Tom Verelst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!