Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

605
Views
webelement selenium - how to found an element with xpath and link with onclick

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 !

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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')]"));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!