mardi 17 avril 2018

Selenium: How to relate a id or class to an specific div?

First post here!

So, I'm totally new with SQA, and my Java knowledge is near to 0 LOL. I'm just trying lo learn as much as i can but at some point i got stucked always

I tried to search before asking but didnt find (or understand) the right answer for my issue. Let me explain it:

I'm testing some charts (powered by highcharts 6). I have 6 different charts on the same url, each one "is" a div container wich has the different elements inside it (buttons etc...)

So the class or/and ID for all the buttons are same, for example: Maximize/Minimize button for chart1:

a class="has-tooltip btn btn-default change" role="button" title="" id="table" data-original-title="TEXT">
<span class="fa fa-lg ik-wi-icon-th"></span></a>

And here the same button for chart2:

<a class="has-tooltip btn btn-default change" role="button" title="" id="table" data-original-title="TEXT">
<span class="fa fa-lg ik-wi-icon-th"></span></a>

Exactly the same. So I tried to use Katalon Recorder to figure out how it can notice that i am clicking different buttons this is what i get:

driver.findElement(By.xpath("//a[@id='table']/span")).click(); click1
driver.findElement(By.xpath("//a[@id='table']/span")).click(); click2

driver.findElement(By.xpath("(//a[@id='table']/span)[2]")).click(); click1
driver.findElement(By.xpath("(//a[@id='table']/span)[2]")).click(); click2

Where it comes this [2]? How can i do to tell selenium wich button i want to click? Sorry for my low skills and bad english, thanks in advance and cheers from Basque country!

Aucun commentaire:

Enregistrer un commentaire