-1

WORKING:

(//div[@role='option'][3])[2]

NOT WORKING:

(//div[@role='option'][1])[2]

I am using those for Selenium Python I am able to select Options from a Dropdown - except Option #1 - this also occurs ONLY starting from the second Dropdown...

I'm kinda stuck and just want to know whats the difference and why its not working?

PRR
  • 13
  • 4
  • You've provided no input markup, and you've not defined "working". The two XPath expressions obviously only differ in the inner index. If you're confused, we can only guess why, but it's likely because you don't understand that the inner index (without precedence-changing parens) means to select all `div` elements that are the n-th child of their respective parent. (See duplicate link for further details.) There may be more or less than `2` such elements, so the behavior may differ from what you expect. If you need more help, [edit] your questions and provide a proper [mcve]. – kjhughes Jan 12 '22 at 00:10

1 Answers1

0

they both take a query of @role='option' anywhere on the page using //. the 1st option takes the 3rd inner element of role='option' and the 2nd inner inner element to return.

The second one takes the 1st inner element of role='option' and the 2nd inner inner element to return. so the difference is they both return different items. One may be trying to return something that isnt there. [#] refers to an index position in this case.

Would suggest posting a full example of the problem using your code, the site, and anything you've tried to do to fix the problem! GL