Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

609
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda