Search This Blog

Monday, May 19, 2014

Reaching Parent Element via Child-Selenium

I'm sure most of people those who do Automation have faced a very typical scenario where , they need to choose a web element within page through another webelement.

Like If there is a player table having 2 columns(Player Name,Player Age)and if a scenario has been given for automation such as 'Verify the Age of Sachin Tendulkar', it becomes a headache to think of using loops after loops.

Whereas Xpath has the power to overcome this kind of scenario: -

Problem: Navigate to Detail view of 'TestX' rule



Solution : Its as simple as the below xpath : -

//td[contains(text(),'TestX')]/..//a[text()='Detail']

Above xpath can be split into 3 parts : -

//td[contains(text(),'TestX')]-The Child Element
//td[contains(text(),'TestX')]/..-The Parent Table
//td[contains(text(),'TestX')]/..//a[text()='Detail']-The Parent Xpath

No comments:

Post a Comment