1

//I have tried alias,asserts,wait,etc..,but can't click the element because the page is not loaded.I don't want to use wait() or pause() command. I need a solution to interact with the elements however the network or testing environment is slow or speed.

My code is as follows :

///

it('Test ship',function(){

cy.viewport(1120,800)

  cy.visit('url')

 cy.get('#NFR_LoginForm-nfr_login_authname').type('KKV2C123')

 cy.get('#NFR_LoginForm-nfr_login_authid').type('paSSword1{enter}')

 cy.on('uncaught:exception', (err, runnable) => {
     return false
 })
 
 cy.wait[ cy.xpath('//span[normalize-space()="Work Space"]')
      
           .click({force: true})]

Here is my screenshot.

Assertion error image

razeem
  • 43
  • 6

2 Answers2

2

Bump the wait time on your click(). Is 3 minutes enough?

cy.xpath('//span[normalize-space()="Work Space"]', {timeout:180000})
  .click()
TesterDick
  • 3,830
  • 5
  • 18
  • The increase of wait can make the element clicked.But by not waiting can u give me a solution.I don't want to use wait and pause. – razeem Mar 17 '22 at 11:21
  • 1
    Cypress' use of "waiting" isn't the same as Selenium's. In this case, if the element is found in under 3 minutes, then the test will resume. The `timeout` only tells Cypress a maximum amount of time to wait, not an exact amount of time to wait. – agoff Mar 17 '22 at 13:57
1

Try something along these lines below:

...
cy.visit('http://70.207.7.25:8070/main')
// mark our window object to "know" when it gets loaded
cy.window().then(w => w.beforeLoad = true)
// initially the new property is there
cy.window().should('have.prop', 'beforeLoad', true)
// after reload the property should be gone
cy.window().should('not.have.prop', 'beforeLoad')
...

This will give a window a new property which will be tracked on page switch and should give it kind of a "pause" to wait for the property not to be available after page loads

Nikola Gavric
  • 3,507
  • 1
  • 8
  • 16