Error message when trying to copy from clipboard in Cypress

43 Views Asked by At

I'm using the following code to obtain a URL that I copied to the Clipboard using a previous Stack Overflow answer:

cy.get('.download-link-wrapper > .download').click().then(($clipboard) => {console.log($clipboard);
       const copiedLink = $clipboard[0]._vClipboard.clipboardAction.text
       cy.visit(copiedLink);
 });

However, I'm receiving the following error message:

Cannot read properties of undefined (reading 'clipboardAction')

Any help would be appreciated.

1

There are 1 best solutions below

0
celoaga On

try this.

cy.window().then((win) => {
    const yourCopiedLink =  win.navigator.clipboard.readText();
});