XPath: XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. XPath was defined by the World Wide Web Consortium. (Wikipedia)
I recorded one script now and here are the steps:
- Open www.flipkart.com
- Search for “Software Testing” books
- Click on the first search result (link)
After running the above script I did not come across any errors, now I want to search for “Selenium Testing” and want to click on the first search result
Did you observe that, I have not changed the last line of the script, which says clickAndWait a link? Okay, let me run the script and see the result.
Wow!! It got PASSED without any errors. How it is possible? It is not pointing to the link name, whereas it is pointing to the Path of the link.
Then what we need to modify to make this script working. Add the Xpath of the link in the script. To find the Xpath I used Firebug add-on of Firefox (You can also use XPather add-on). Then I changed the script with Xpath (It looks like)
And yes, now my script is working as intended.
Do you have any other examples for Xpath, please do share with me.
Happy Learning – Happy Testing