antonio nehme
antonio nehme

Reputation: 21

Click Button With No ID Selenium Java

Apologies for this;

  • Event Triggers
  • Photos
  • Push Notifications
  • How can I Click on Event triggers for example using Selenium Java?

    I've tried this code:

    By.xpath("//button[contains(text(),'Event triggers')]"); By.xpath("//button[contains(text(),'Submit')]");

    I tried this as well:

    WebElement Box= driver.findElement(By.tagName("Event triggers")); Box.submit();

    Neither of these worked...

    Thank you

    Upvotes: 0

    Views: 2293

    Answers (4)

    ChrisJavaPython
    ChrisJavaPython

    Reputation: 1

    The correct answer is:

    By.xpath("//button[contains(text(),'Event triggers')]").click(); 
    

    You were missing that click action.

    Upvotes: 0

    E.E
    E.E

    Reputation: 9

    Well, if button doesnt have any id , you can try to write dynamic xpath by using "class name" and "type" (there are plenty of examples , you can learn easily how to create your xpath) , or easiest way, use firebug to locate element that you want to click and copy exact Xpath via firebug. And then click.

    Upvotes: 0

    Swapnil Pingle
    Swapnil Pingle

    Reputation: 40

    Based on the page source mentioned in the comment I think Event Triggers is not a button but an tag which essentially makes it a link. As you know the text of the link you are trying to click you can always use:

    driver.findElement(By.linkText("Event Triggers"));
    

    to get Event Triggers web element.

    Using xpath should be avoided due to slow performance.

    Upvotes: 0

    Try to using this:

    By.xpath("//a[contains(text(),'Event triggers')]");  
    

    instead of

    By.xpath("//button[contains(text(),'Event triggers')]"); 
    

    Upvotes: 1

    Related Questions