Distinguishing between elements with the same name in RobotFramework

1.7k views Asked by At

I have a website with a table of links inside of it. There are two/three elements (links) in the table with the same name. The only thing that distinguishes them is the header above them

< h1 class="b4">Label 1< /h1>

Would be an example. How can I get RF to go the link under the header Label 2 as opposed to Label 1? I need something besides xpath/css because those change throughout the design.

1

There are 1 answers

0
Würgspaß On

Given your example

<div class="bU"> 
<h1 class="b4">Header 1</h1> 
<a data-ajax="" class="b5" href="Link">Link1</a> 
<h1 class="b4">Header 2</h1> 
<a data-ajax="" class="b5 ca" href="Link">Link1</a>
</div>

the easiest (XPath) way to access the anchor elements is directly using their unique class attributes:

//a[@class='b5']

for the first

//a[@class='b5 ca']

for the second.

If - for whatever reason - you have to use a locator relative to the headers, use this (for the second anchor element):

//h1[text()='Header 2']/following::a