Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

607
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda