How to find an element with Xpath with an attribute and without another attribute

This is my Xpath request:

driver.findElements(By.xpath("//*[@id=\"continue-button\" and not(contains(@class=\"disabled-button\"))]")); 

I am having trouble finding an item with the continue button id, and not with the disabled button class. I am clearly writing the request incorrectly, but I am not sure about this problem. I am not familiar with the Xpath syntax to use in this situation.

+6
source share
1 answer

Your xpath:

 //*[@id=\"continue-button\" and not(contains(@class=\"disabled-button\"))] 

Must be:

 //*[@id="continue-button"][not(contains(@class, "disabled-button"))] 

I highly recommend if you use Firebug to install something like firepath , to test your xpath expressions before running them in tests.

Edit: for those who can see this in the future, tools like Firebug are no longer needed. Newer versions of browsers now allow you to enter XPath and CSS expressions in the corresponding DOM-viewer. For example, in Chrome, the F12 hotkey will open the debugging tool, and the Ctrl + F hotkey on the Elements tab will open the search panel where you can enter selection expressions.

+3
source

Source: https://habr.com/ru/post/954198/


All Articles