Search code examples
javahtmlxpathautomationonclick

Click() event not working over a button (XPATH)


I'm trying to get a Click() event on this button (called: Add PRODUCT) but it is not working, working on a JAVA automation.

image

I'm getting this XPATH:

//*[@id="order-items"]/div1/div/button1/span

This is the FULL XPATH:

/html/body/div3/main/div2/div/div/form/div[5]/div/div1/section1/div1/div/button1/span

So, I'm trying to do something like this:

driver.findElement(By.xpath("//*[@id="order-items"]/div[1]/div/button[1]/span")).click();

What am i doing wrong?

EDIT#1:

If i click on "ADD PRODUCT" i got this XPATH:

//*[@id="add_products"]

EDIT #2

IMAGE

I got this:

xpath: //*[@id="order-items"]/div1/div/button1


IMAGE

I got this:

xpath: //*[@id="add_products"]


Solution

  • first, .click() will only work on html active tags. second, focus directly on the button.

    driver.findElement(By.xpath("*//button[@id='add_products']").click();