Issue
I try to get element like this :
webDriver.findElement(By.xpath("//a[contains(@onclick="submitData('updateShortcodeAdmin','')")]"));
or like this :
webDriver.findElement(By.xpath("//a[contains(@onclick=\"submitData(\'updateShortcodeAdmin\',\'\');")]\"));
or like this :
webDriver.findElement(By.xpath("//a[contains(@onclick=\"submitData(\'updateShortcodeAdmin\',\'\')\")]"));
and got the same Error :
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //a[contains(@onclick="submitData('updateShortcodeAdmin','')")] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[contains(@onclick="submitData('updateShortcodeAdmin','')")]' is not a valid XPath expression.
What am I writing wrong?
Thanks !
Solution
Please use the below xpath :
//a[contains(@onclick,'submitData('updateShortcodeAdmin')')]
Explanation :
You are using =
in contains method, it should have been ,
I checked in compiler that
webDriver.findElement(By.xpath("//a[contains(@onclick,'submitData('updateShortcodeAdmin')')]"));
does not show any compile error.
PS : Please check in the dev tools
(Google chrome) if we have unique entry in HTML DOM
or not.
Steps to check:
Press F12 in Chrome
-> go to element
section -> do a CTRL + F
-> then paste the xpath
and see, if your desired element
is getting highlighted with 1/1
matching node.
Update :
webDriver.findElement(By.xpath("//a[contains(@onclick,'updateShortcodeAdmin')]"));
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.