golu
golu

Reputation: 849

Not able to get element by xpath index (selenium)

I am trying to get a element in a list by specifying index

For example I have this xpath:

"//p-dropdown[@formcontrolname='PrimaryRoleId']//ul[contains(@class, 'ui-dropdown-items')]//li[contains(@class, 'ui-dropdown-item')]" and it gives me this:

enter image description here

But when I add [1] at the end of xpath I still get the same thing? How can I get the first (or specific matching element by index)? enter image description here

Upvotes: 0

Views: 105

Answers (1)

Ashok Kakade
Ashok Kakade

Reputation: 61

Can you try to enclose it with parenthesis "()"

(//p-dropdown[@formcontrolname='PrimaryRoleId']//ul[contains(@class, 'ui-dropdown-items')]//li[contains(@class, 'ui-dropdown-item')])[0]

Upvotes: 1

Related Questions