Ripon Al Wasim
Ripon Al Wasim

Reputation: 37756

Difference between various types of xpath used in Selenium WebDriver

I have the following snippet of HTML code:

<div id="divTooltips_Section_Filter" style="float:right; padding-right: 30px; padding-bottom: 10px;">
<img src="/mkteditor/css/images/tooltip.png" width="25px" height="25px" alt="">
</div>

I wrote the xpath as following ways:

1. //*[@id='divTooltips_Section_Filter']/img
2. //div[@id='divTooltips_Section_Filter']/img

Both of the xpath mentioned above worked fine. What's the basic/main difference between them? Is there any performance issue for WebDriver?

Upvotes: 0

Views: 569

Answers (1)

Vincent Biragnet
Vincent Biragnet

Reputation: 2998

Your first query looks for every element in the document and applies the filter on the id attribute and then find all img children of the filtered elements.

Your second query looks for every div element in the document and applies the filter on the id attribute and then find all img children of the filtered div element.

The two queries may return different results.

If in your case (given the document you expect as input), you know that the two queries will return the same results, then the second query should perform better (if your XPath processor is not badly implemented), because tests on attributes will be performed on a subset of the elements in the document.

Upvotes: 1

Related Questions