Wildcard characters in XPath – Selenium WebDriver

We generally use an asterisk (*) while writing XPaths. This is called a Wildcard character.

An asterisk in XPath may represent any node or attribute name of XML or DOM. A node is a tag in XML document. When we do not bother about node or attribute name we can use an asterisk. For example:-

//span -> Only span node/s

//* -> Any node/s

//div//* -> Any child node of any parent node “div”

An asterisk can help us with attribute names as well. For example:-

//input[@*=’demo’] -> Any “input” node who contains an attribute value as “demo” for any attribute.

//a[@*] -> Any ‘a’ node who contains any attribute

//a[contains(@*,’demo’)] -> Any ‘a’ node whose any attribute value contains “demo”.

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related posts here, all API manual and automation related posts here, and find frequently asked Java Programs here.

Many other topics you can navigate through the menu.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.