Build different XPATH expressions for the same HTML element

One of the difficult things to learn for testers that are new in test automation is selecting HTML elements in XPATH.

In order to click, select, type text in HTML elements, they need to be found first.

I have created a few different expressions that identify the same element of a page.

This is how to find the element matched in the next examples:

1. open

2. search for cats

3. identify the title link for the 7th result

Please click on the images from below to see them full screen.





//a[contains(@title, 'Book') and contains(@href, '1921954038_cats')]

All expressions do the same thing in different ways.

They are presented only to highlight the flexibility and power of XPATH.

From all 5 example expressions, the only one that I would use in my projects is the 3rd one.


Do you want to learn more about test automation and Java?
I will start an SELENIUM online group training on October 15.
Please see the training details here.

Share this