<<Previous Post << Complete Tutorial>> Next Post>
Selenium Locators – XPath Expression – Wild cards
The following are the two wild cards, we can use in the XPath Expression:
- *
- node()
I have already, demonstrated the * wild card in the previous articles on Relative XPath Expression.
In this article, I am going to explain the other wildcard i.e. node().
Before practically demonstrating node() in XPath Expressions, we need to understand the differences between * and node() wild cards.
1) * can be used in XPath Expressions to represent any tag or any attribute name.
Whereas node() can only be used to represent any tags.
2) * is the most used wild card in XPath Expressions.
Whereas node() is least used and can be replaced using * anyhow.
Though node() is least used, we need to know about it for knowledge and interviews purpose.
3) node() should not be used at the end of the Expression. i.e. XPath Expressions should not end with node() wild card. If we add node() at the end of XPath Expression, it becomes invalid.
For example: /html/body/node() is an invalid XPath Expression
Example of valid XPath: /node()/node()/p[1]
Hope, you understood about node() wild card usage in XPath Expressions.
Lets practically use the node() in the XPath Expressions using the below steps:
1) Open http://compendiumdev.co.uk/selenium/basic_web_page.html in Chrome Browser, where ChroPath is already installed (Refer ChroPath installation in Chrome Browser here and its usage in Chrome Browser here ) as shown below:
2) Open ‘ChroPath’ functionality as shown below in the Chrome Browser:
3) Select ‘Abs XPath’ option from the ‘Selectors’ dropdown as shown below:
4) Let’s Execute the below Absolute XPath Expression in ChroPath as shown below:
Absolute XPath Expression: /html/body/p[1]
Now, replace the html and body tags in the above Absolute XPath Expressions with node() wild card as shown below:
/node()/node()/p[1]
Also, you can only replace the body tag in the above Absolute XPath Expression with node() wild card as shown below:
/html/node()/p[1]
5) Select ‘Rel XPath’ option from the ‘Selectors’ dropdown as shown below:
6) Let’s Execute the below Relative XPath Expression in ChroPath as shown below:
Relative XPath Expression: //body/p[1]
Now, replace the body tag in the above Relative XPath Expressions with node() wild card as shown below:
//node()/p[1]
Here ends this article on wild cards.
In the next article, I will demonstrate the next set of Relative XPath Expressions in a practical way.
Next Steps:
- > To learn more about Selenium, continue to the next post (Click on Next Post link below)
- > Check complete Selenium Tutorial Contents here (Click here)
Please leave your questions/comments/feedback below.
Happy Learning ?
On a mission to contribute to the Software Testing Community in all possible ways.
<<Previous Post << Complete Tutorial>> Next Post>
Hi Arun, thanks for explaining about node() wildcard. It would be helpful if you can let me know on below questions.
1. Where exactly we will be using node() wildcard?
2. What types of questions will be asked on node()?
Hi Sandeep.
I have explained it in the article.
Please check.