razeem
razeem

Reputation: 43

Expected to find element : but never found it(not a normal assertion)

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

Upvotes: 1

Views: 2423

Answers (2)

TesterDick
TesterDick

Reputation: 10525

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

cy.xpath('//span[normalize-space()="Work Space"]', {timeout:180000})
  .click()

Upvotes: 2

Nikola Gavric
Nikola Gavric

Reputation: 3543

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

Upvotes: 1

Related Questions