This is my Xpath query:
driver.findElements(By.xpath("//*[@id=\"continue-button\" and not(contains(@class=\"disabled-button\"))]"));
I am having trouble locating the element with the id of continue-button and not the class of disabled-button. I am obviously writing the query wrong, but I am not sure of the issue. I am unfamiliar with the Xpath syntax to use in this situation.
Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.
The XPath default axis is child , so your predicate [*/android.widget.TextView[@androidXtext='Microwaves']] is equivalent to [child::*/child::android.widget.TextView[@androidXtext='Microwaves']] This predicate will select nodes with a android. widget. TextView grandchild and the specified attribute.
Your xpath:
//*[@id=\"continue-button\" and not(contains(@class=\"disabled-button\"))]
Should be:
//*[@id="continue-button"][not(contains(@class, "disabled-button"))]
I highly suggest if you use Firebug to install something like firepath to test out your xpath expressions before running them in tests.
Edit: For anybody who may see this in the future, tools like Firebug are no longer necessary. Newer versions of browsers now allow you to enter XPath and CSS expressions in their respective DOM-viewer. For example in Chrome, the hotkey F12 will open the debug tool, and the hotkey Ctrl+F while on the "Elements" tab will open a search bar which you may enter selector expressions into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With