I am working on a web page which having 3 web elements with 3 enable buttons and all buttons having same Xpath.so my need is to click on the button A and print the title of the webelement on every login and logout operation.

  • It is not possible for two elements to share the same Xpath.
    – Yu Zhang
    Commented Apr 24, 2017 at 10:12
  • Refer my answer in this link https://sqa.stackexchange.com/questions/26436/how-to-handle-if-xpath-is-same-for-multiple-drop-down/26439#26439
    – Sagar007
    Commented Apr 24, 2017 at 10:27
  • Can you add the DOM screen of your application for this scenario?
    – Bharat Mane
    Commented Apr 24, 2017 at 10:33

1 Answer 1


In my case, How I worked on this same scenario: Suppose if you have 3 buttons with the same XPath-like in my DOM:

<input type="submit" id="button" value="Edit"/>
<input type="submit" id="button" value="Edit"/>
<input type="submit" id="button" value="Edit"/>

The best option to overcome this situation is:

1. By XPath indexing option:

By.xpath("(//input[@type='submit'])[0]")  ---> To Click 1st Button
By.xpath("(//input[@type='submit'])[1]")  ---> To Click 2nd Button
By.xpath("(//input[@type='submit'])[2]")  ---> To Click 3rd Button


XPath = "//input[@id='button' and @value='Edit'][0]
XPath = "//input[@id='button' and @value='Edit'][1]
XPath = "//input[@id='button' and @value='Edit'][2]

2. BY generating Absolute XPath from starting Node to Descent Node:


3. Use of List web elements:

    String cssSelectorOfBtn="input[type='submit'][id='button']"; 
 //****Add cssSelector of your 1st webelement

    List<WebElement> button =driver.findElements(By.cssSelector(cssSelectorOfBtn));

Let me know if it works...

  • The result gave a IndexOutOfBoundException actually doesn't solve my problem Commented Dec 25, 2020 at 22:11
  • @rabiacatak If you're having a problem, try to isolate it and, if necessary, ask a new question. Thanks!
    – corsiKa
    Commented Dec 26, 2020 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.