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

317
Visualizações
problem with find an element using cypress and xpath

I'm trying write a code (using cypress) to bypass long press verification such that verification image

this is inspect>> id and class values are changes every session <p id="oVzBRZgfQmDATFj" class="NMBmfXVZnqeiNEY" style="animation: 111.8ms ease 0s 1 normal none running textColorIReverse;">Press &amp; Hold</p>

I was tried XPath Selectors and i get the following: //p[text()='Press & Hold']

//p[starts-with(text(),'Press & Hold')]

//p[position()=1]

//p[normalize-space()='Press & Hold']

//p[last()]

//p[contains(text(),'Press & Hold')]

//p[contains(normalize-space(),'Press & Hold')]

//p[.='Press & Hold']

After experiment each of them such as element:

cy.xpath('//p[starts-with(text(),"Press & Hold")]').trigger('mousedown')
cy.wait(10000)
cy.xpath('//p[starts-with(text(),"Press & Hold")]').trigger('mouseup')

This error appears: Timed out retrying after 4000ms: Expected to find element: //p[starts-with(text(),"Press & Hold")], but never found it. error image

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

0

If you don't have access to modifying selectors in the app, an easier approach would be to use .contains().

Assuming your <p> contains the events needed to verify, you can simply get the jquery element with the following:

cy.contains('p', 'Press & Hold')

I'm not sure if the verification process requires the user to be holding the click for 10 seconds, but i'm sure you can do less time.

If the .trigger() is not verifying, which could be guarded against, you can try using .realClick() from the cypress-real-events plugin.

about 4 years ago · Juan Pablo Isaza Relatório

0

The code you have used succeeds in a simple test.

Using the following in a simple (isolated) test works

<p>Press &amp; Hold</p>
cy.xpath('//p[starts-with(text(),"Press & Hold")]')
    .trigger('mousedown')  
...
})

Testing with redirect to new origin

cy.origin('redirect-url-after-login', () => {

  cy.xpath('//p[starts-with(text(),"Press & Hold")]')
    .trigger('mousedown')  
  cy.wait(10000)
  cy.xpath('//p[starts-with(text(),"Press & Hold")]')
    .trigger('mouseup')

})

You must turn on this experimental feature in Cypress config

// cypress.json

{
  ...
  "experimentalSessionAndOrigin": true
}
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