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 & 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
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.
The code you have used succeeds in a simple test.
Using the following in a simple (isolated) test works
<p>Press & 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
}