'Child tab with NO target attribute in Cypress

I got a really tough issue while writing the scripts in Cypress. I clicked an element and it directs to a new page. I want to click the next element on the new page. I know that Cypress doesn't allow to work on a new window simultaneously.

So I tried solving with many solutions available in the web.

I got the same error that it could not click the element on the new tab. I have attached the html body of the screen. Can someone please help me out to solve the issue.

This is the html body

The following was my code..

/// <reference types="cypress" />

describe('ship test',() =>{
it('first test',() =>{
cy.viewport(1120,800)
cy.visit('url')
cy.get('#LoginForm-login_authname').type('12345)
cy.get('#LoginForm-login_authid').type('12345{enter}')

cy.on('uncaught:exception', (err, runnable) => {
return false
})

cy.wait[cy.xpath('//span[normalize-space()="Work"]')
.click({force: true})]

cy.xpath('//*[@id="VTK-j_idt1184"]',{timeout : 700000}).click()
cy
.window().then((win) => {
cy.spy(win, 'open').as('redirect');
});
cy
.xpath('//a[@class="ui-commandlink ui-widget btn_wrapper pull-right createtask_btn"]',{timeout : 700000})
.click();
cy
.get('@redirect')
.should('be.calledWith', 'href', '/about');
})
})

The error.. This is the imageenter code here



Solution 1:[1]

It looks like this

cy.xpath('//*[@id="VTK-j_idt1184"]',{timeout : 700000}).click()

and this

cy.xpath('//a[@class="ui-commandlink ui-widget btn_wrapper pull-right createtask_btn"]',{timeout : 700000})
.click();

are trying to click the same link.

Try removing the 1st one. (you need to click after the spy is set).

To test the new tab, is easiest to visit in a new test.

it('tests the about tab', () => {
  cy.visit('/about');
  ...

Footnote

If click() does not work, you may have more luck trying .realClick().

See Cypress Real Events written by Dmitriy Kovalenko (Ukraine).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1