HomeSelenium

Selenium Locators – XPath Expressions – Wild cards

Selenium Locators – XPath Expressions – Wild cards

<<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:

  1. *
  2. 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:

Absolute XPath - Opening Basic Application

2) Open ‘ChroPath’ functionality as shown below in the Chrome Browser:

Absolute XPath - Open ChroPath

3) Select ‘Abs XPath’ option from the ‘Selectors’ dropdown as shown below:

Absolute XPath - Abs XPath

4) Let’s Execute the below Absolute XPath Expression in ChroPath as shown below:

Absolute XPath Expression:  /html/body/p[1]

XPath Expressions - Wild cards - XPath One

Now, replace the html and body tags in the above Absolute XPath Expressions with node() wild card as shown below:

/node()/node()/p[1]

XPath Expressions - Wild cards - XPath node one

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]

XPath Expressions - Wild cards - XPath node two

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]

XPath Expressions - Wild cards - XPath Two

Now, replace the body tag in the above Relative XPath Expressions with node() wild card as shown below:

//node()/p[1]

XPath Expressions - Wild cards - XPath Two Locates

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 🙂

About Me > Arun Motoori

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                            << Complete Tutorial>>                              Next Post>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *