Reputation:
I need to click on first row of the data table.But this data table will vary always according to the user.How I can create xpath for those kind of dynamic elements?
<div id="periodAccordion">
<h3 id="p5-header" onclick="periodOnClick('5','2016')">Period 5</h3>
<div id="p5">
<h3 id="p3-header" onclick="periodOnClick('3','2016')">Period 3</h3>
<div id="p3">
<h3 id="p2-header" onclick="periodOnClick('2','2016')">Period 2</h3>
<div id="p2">
<h3 id="p1-header" onclick="periodOnClick('1','2016')">Period 1</h3>
<div id="p1">
<h3 id="p10-header" onclick="periodOnClick('10','2015')">Period 10</h3>
<div id="p10">
<h3 id="p8-header" onclick="periodOnClick('8','2015')">Period 8</h3>
<div id="p8">
</div>
Here I need to create xpath for first element.its attibutes is:
<h3 id="p5-header" onclick="periodOnClick('5','2016')">Period 5</h3>
<div id="p5">
How can i create xpath for this element?Here all the elements will vary when i login with a other user.
Upvotes: 0
Views: 1045
Reputation: 3004
if you always want to select the first row, use the below xpath:
//h3[contains(@id,'header') and contains(@onclick,'periodOnClick') ][1]
hope this will help you and let me know what happens.
Upvotes: 1
Reputation: 4173
You could use the following xpath to select the first h3
:
//div[@id='periodAccordion']/h3
if you need for the first div
from the main div, then:
//div[@id='periodAccordion']/div
If you need only the firs one then you can use:
//div[@id='periodAccordion']/h3[1]
Upvotes: 0