I am new to selenium and I really have hard times here with dynamic buttons. I am writing selenium webdriver js scripts
I searched on stackoverflow and found few pages with similar errors posted but none of them solved my problems
I want to use this xpath
/dom[@domain='localhost:3000']//div[#'search-results']//button[@innertext='Add Contact']
and here is my code
driver.wait(until.elementIsVisible(driver.findElement(By.xpath("/dom[@domain='localhost:3000']//div[#'search-results']//button[@innertext='Add Contact']"))))
and get this error
InvalidSelectorError: invalid selector: Unable to locate an element with the xpa
th expression /dom[@domain='localhost:3000']//div[#'search-results']//button[@in
nertext='Add Contact'] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '/dom[@domai
n='localhost:3000']//div[#'search-results']//button[@innertext='Add Contact']' i
s not a valid XPath expression.
and here is the html
<button class="btn btn-success btn-sm pull-right" data-email-id="[email protected]" data-user-id="[email protected]" data-name="user3 test">Add Contact</button>
Can you help me identify my problem ?
#search-results can be used in CSS selectors for id attribute with value 'search-results'. In XPath you should use @id='search-results'
As @JeffC pointed out [@innertext='Add Contact'] predicate should be replaced with [.='Add Contact']
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