Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!