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

222
Visualizações
How to click on element having both string and random number using selenium javascript
<a id="Message4217" class="btn-sm btn-danger Message" data-id="4217"><span class="icon-adjustment icon-trash"></span> Delete</a>
  1. Goal is to delete a message based on the selection criteria

  2. For every message, it has text and a random number (i.e) "Message4217"

  3. How can we select and click for random numbers

  4. I am not able to use xpath because every different message generates random numbers

    //*[@id="Message4217"]
    
    //*[@id="Message4218"]
    
  5. Is there a way to select such type of elements

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Looks like this element can be located based on 2 parameters:

  1. The partial id value
  2. The text

If so it will match this XPath:

//a[contains(@id,'Message') and text()='Delete']

There is a span element inside it, we can add this dependency as well so the locator will be:

//a[contains(@id,'Message') and text()='Delete' and ./span[@class='icon-adjustment icon-trash']]
about 4 years ago · Juan Pablo Isaza Relatório

0

It's better to use this xpath:

//a[starts-with(@id,'Message')]

or the below css:

a[id^='Message']

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/css and see, if your desired element is getting highlighted with 1/1 matching node.

if there are let's say nth matches then you can use findElements with the XPath of CSS and then can iterate or use the index to click on the button.

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