2.3 Multiple Elements Handling

When we have multiple elements to work with, and wish to use few of them based on business requirement, then we need a logical loop to take those decisions. In this demo we will be demonstrating how we can make a choice based action.

Below is the snapshot of seleniumhq.org website. Using firebug and firepath I have calculated a xpath : “.//*[@id='header']//li/a” which highlights all the seleniumhq links on the header. We use this xpath to fetch all these links in our code and then click the link that matches the link text of our choice. In this demo it will be “Documentation”. More on xpath in our tutorial Robust Xpath.

Xpath

In the code below we are using cssSelector instead of xpath, to use xpath uncomment the xpath code and comment cssSelector code block.

Last updated

Was this helpful?