I am unable to find dynamic xpath for below code

<input class="login_button" type="submit" tabindex="3" id="@COMMAND_EVENT@" name="@COMMAND_EVENT@" value="Submit" style="top: 20px; left: 360px; width: 60px; height: 20px; position: absolute">


  1. //*[contains(@tabIndex,"3") AND contains(@class="login_button")]
  2. //input[contains(@tabIndex,"3") AND contains(@class="login_button")]
  3. //input[@name,'@COMMAND_EVENT@'][tabIndex,'3']

Note: tabIndex used twice for other element too

2 Answers 2


You can try following xpath to click on said element


Make sure you see only 1 found while evaluate the above xpath in browser else you need to take some surround element to make the xpath unique

Additionally, You can use JavascriptExecutor to perform the click.

Java code sample:

WebElement element = driver.findElement(By.xpath("//input[@class='login_button'][@type='submit']"));

JavascriptExecutor js = (JavascriptExecutor)driver; 

js.executeScript("arguments[0].click();", element);  
  • Thanks Narendra for the help...i am able to click now...
    – Rahul
    Jan 23, 2019 at 11:24

I am not sure this contains(@class="login_button") is a proper xpath syntax (however since you're not mentioning parse errors looks like it is) at least for your task.


  1. //*[contains(@tabindex,"3") and contains(@class, "login_button")]

  2. //input[contains(@tabindex,"3") and contains(@class, "login_button")]

  3. //input[@name='@COMMAND_EVENT@'][@tabindex='3']

What matters here:

  • you have tabindex but use tabIndex in your queries (it has different letter case)
  • the parser that I used for test didn't accept AND in upper-case but worked fine with lowercase and
  • Thanks Alexey for Answer however when i tried below xpath //input[@name='@COMMAND_EVENT@'][@tabindex='3'] then also i am unable to click on submit button....not sure why ...and console shows no error Note: //input[@name='@COMMAND_EVENT@'][@tabindex='3'] found unique value when searched in chrome inspect element.
    – Rahul
    Jan 22, 2019 at 10:28
  • may be it is disabled? The fact you have successfully located an element does not guarantee you will be able to interact with it.
    – Alexey R.
    Jan 22, 2019 at 10:31
  • What are the other ways to successfully click the element? Can you please help..
    – Rahul
    Jan 22, 2019 at 10:36
  • 1
    I am not getting you. What do you mean? The only way to succesfully click an element is to locate it and invoke click() for that element. If you are not able to click using this approach that your UI likely makes the interaction not possible. There are hundred different reasons (it is hidden under other elemetns, you have not provided required data so javascript blocks the interaction, etc).
    – Alexey R.
    Jan 22, 2019 at 10:41

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.