Book Image

Learning Selenium Testing Tools - Third Edition

Book Image

Learning Selenium Testing Tools - Third Edition

Overview of this book

Table of Contents (22 chapters)
Learning Selenium Testing Tools Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Leveraging the XPath axis with elements


As we have seen, XPath is normally only used if the element we need to interact with is not accessible by normal means. In this section of the chapter, we will have a look at leveraging the XPath axis in our queries to find the element that we wish to interact with. An example that I have used in the real world was to find a table cell that had specific text, then traverse the tree backwards to find the edit button so that I can click on it. This may seem laborious just to click on an edit button, but it is extremely common according to the Selenium users forum on Google Groups.

Using the XPath axis

In the first example, we found a button and then its sibling. In this example, the query that we will generate is equivalent to xpath=//div[@class='leftdiv']/input[2].

  1. We will start by finding the first element for our query, which is //input[@value='Button with ID']. Place this element into the Selenium IDE Target textbox and see which element it highlights...