Home > Net >  Not able to get element by xpath index (selenium)
Not able to get element by xpath index (selenium)

Time:10-22

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

CodePudding user response:

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]
  • Related