Reputation: 2578
I am tring to find a button in a webpage using find elements, the page can contain one of the below button ID's.
driver.findElements(By.xpath("//*[contains(@id,'topBtn')]"))
driver.findElements(By.xpath("//*[contains(@id,'WSMplasticTop')]"))
driver.findElements(By.xpath("//*[contains(@id,'bottomApplyBtn')]"))
The above code is working as expected when i use the Firefox Driver, where as getting the below error when i run in Chrome Driver.
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[contains(@id='bottomApplyBtn')] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[contains(@id='bottomApplyBtn')]' is not a valid XPath expression.
Just wanted to know whether i have done any mistake
Upvotes: 0
Views: 488
Reputation: 3235
When you are using contains
method in your XPath
expression, you basically are using an inbuilt method
to find the element.
This method takes 2 parameters.
Basically you have to call the method with 2 parameters and that 2 parameters should be comma
separated.
So //*[contains(@id='bottomApplyBtn')]
is wrong you should instead remove this =
sign.
//*[contains(@id, 'bottomApplyBtn')]
|_______|____________________ Parameter 1
|__________________________________Parameter 2
Hope it helps!
Upvotes: 1
Reputation: 52665
Try to use
'//*[contains(@id,'bottomApplyBtn')]'
instead of
'//*[contains(@id='bottomApplyBtn')]'
Upvotes: 2