0

If 3 of the dropdowns like in the screenshots got similar id names and all. How to locate them then? 3 of them have got similar xpaths. How to detect them? enter image description here

  • You can detect all the dropdowns uniquely using different [locator strategies](https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver). – undetected Selenium Aug 03 '22 at 04:37
  • Please [edit] your question to include your code and HTML as **text** rather than as a screenshot. On stack overflow images should not be used for textual content, see [*Discourage screenshots of code and/or errors*](https://meta.stackoverflow.com/a/307500) and [*Why not upload images of code on SO when asking a question*](https://meta.stackoverflow.com/a/285557) for why. For instructions on formatting see *[How do I format my code blocks?](https://meta.stackexchange.com/q/22186)*. A [mcve] showing what you have tried that did not work would maximize your chances of getting help. See [ask]. – dbc Aug 03 '22 at 18:37

1 Answers1

0
  1. You can use findElements to identify all of them and use index to identify them.

    List<WebElement> elementName = driver.findElements(By.xpath("//select[@id='formrow-inputSector']"));
    
  2. You can use relative location strategy like parent, ancestor or child Assuming there is a div containing 'Choose Organization' and choose product inside the select. ( or if select itself contains the text - use text() = 'Choose Organization' - this won't work if there is some other value selected previously)

    WebElement elem = driver.findElement(By.xpath("//select[child::*//*[text()='Choose Organization']]"))
    

or use siblings, ancestors or parent

(https://www.guru99.com/using-contains-sbiling-ancestor-to-find-element-in-selenium.html - For Reference )

zx485
  • 28,498
  • 28
  • 50
  • 59