Friday, October 12, 2018

Chained XPath

We can create a chain of multiple Relative XPath declarations with ' // ' double slash to find an element location as shown below:

Syntax:
//tag[@attribute='value']//tag[@attribute='value']
Example:
//div[@class='form-group']//input[@id='user-message']
Let's get a clear view with the below example:
//li[@class = 'gb_T']//span[@class = 'gb_Z']

Here, //li[@class = 'gb_T']//span[@class = 'gb_Z'] selects all the 'li' elements which contains 'gb_T' as attribute class value and then selects all the 'span' elements which contains 'gb_Z' as attribute class value. //span[@class = 'gb_Z'] selects only those 'span' elements which are the decedent of the 'li' elements selected by //li[@class = 'gb_T'].

No comments:

Post a Comment