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

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

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 Denunciar

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 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