Forum Discussion

pmakkena's avatar
pmakkena
Occasional Contributor
10 years ago

can some help me with xpath for 2 button .

The 2 sample html are

1) <input id="btnMoveRight" class="arrowBtn" type="button" value=" > " onclick="moveRight('Funds')">

2)<input id="btnMoveRight" class="arrowBtn" type="button" value=" > " onclick="moveRight('Reports')">

 

The chrome is suggessting same xpath for both of them i.e//*[@id="btnMoveRight"].

can you please help me how to make unique the above 2 htmls options.

  • Hi Prashant,

    IDs of both buttons are the same. Good approach is to assign different names for different objects.

    Anyway, I noticed that the moveRight function passes different parameters in different objects. You can try using the following XPath expressions:

    //*[@id="btnMoveRight" and contains(@onclick, "Funds")]
    
    //*[@id="btnMoveRight" and contains(@onclick, "Reports")]
  • The another way if you want a shorter xpaths

    (//*[@id="btnMoveRight"])[1]

    (//*[@id="btnMoveRight"])[2]

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Prashant,

    IDs of both buttons are the same. Good approach is to assign different names for different objects.

    Anyway, I noticed that the moveRight function passes different parameters in different objects. You can try using the following XPath expressions:

    //*[@id="btnMoveRight" and contains(@onclick, "Funds")]
    
    //*[@id="btnMoveRight" and contains(@onclick, "Reports")]