1

Observed that the only unique value is id, how can we fetch in this case.

Please Find the HTML :

<div id="0007" data-activity-type="CompatCheck" class="Activity"></div>
                                
<div id="110007" data-activity-type="CompatCheck" class="Activity"</div>

While trying to use following code line :

findElement(By.xpath("//div[@data-activity-type='CompatCheck']")).getAttribute("id");

I'm getting only first id i.e; 0007

but I need always the second id="110007", can you please suggest to get the second id

Expected output : 110007

nayansFosgit
  • 69
  • 1
  • 7
  • If possible please share a link to that page so we will be able to make some minimal check / debugging – Prophet Jan 17 '23 at 15:32
  • Sorry That link has limited access, so even its shared wont be able to access it,have detailly specified html code in this case, could you please look into it https://stackoverflow.com/questions/75152993/how-to-fetch-id-from-div-tag-using-xpath-in-efficient-way – nayansFosgit Jan 17 '23 at 22:50

1 Answers1

2

In case you always need the second element id you can update your XPath accordingly.
This should work:

findElement(By.xpath("(//div[@data-activity-type='CompatCheck'])[2]")).getAttribute("id");
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Hi @Prophet thanks it really worked, I'm getting desired output but sometimes don't looks like I'm missing some where – nayansFosgit Jan 17 '23 at 22:45