I have a situation where i had to handle drop down and click the drop down to select some values. There are two drop down in same page and both has same xpath. The Xpath is giving below.


I know only one way how to handle this, which is adding [1] with the xpath and I tried the below way to handle this.


but it still it is not working.. Is there any other way i can try this?

  • 2
    how is it not working? what exception have you got? – Yu Zhang Mar 28 '17 at 5:03
  • Please include the html in question with the two combo boxes – mutt Mar 28 '17 at 5:23

It might be issue of same level HTML code.

Solution :

1. For First Dropdown :


2. For Second Dropdown :


3. Use element list to get Dropdown :

List<WebElement> lstDrp = driver.findElements(By.xpath("//div[@name='expiryDate']/div/a/div[2]/i"));

4. For more specific and dynamic xpath use below code :


Please let me know If any issue.


If an xpath refers multiple elements on the DOM, It should be surrounded by brackets first () and then use numbering.

if the xpath refers 4 elements in DOM and you need 3rd element then working xpath is (common xpath)[3].

If you are beginner and need more clarity watch https://youtu.be/k-znmPHjTF0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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