Cypress - How to click on cookies "Accept cookies" pop up

Viewed 88

I am not able to click or even detect any element inside of Pop-up cookies on badoo.com enter image description here

I am using all kind of commands like get , contains, etc. nothing works and it tells me that I didnt find element :/

3 Answers

Looks like there is an iframe blocking your test code.

First verify this is so by right-clicking on the button, choose "Inspect element" then scroll up in the Elements panel until you find an <iframe> and find out it's id=... attribute.

To handle the iframe, the simplest way is with the cypress-iframe plugin.

Note the instructions given on this plugin have not been updated for Cypress version 10.

After installing, add require('cypress-iframe'); at the top of the spec.

In the test use the following, but substitute the id you found above for #my-iframe

cy.iframe('#my-frame')
  .find('button[title="Accept Cookies"]')
  .click()

After another research, its enough to find ID of iframe and then put after it .its('0.contentDocument.body') and then its possible to find any element inside of inframe

cy.get('#sp_message_iframe_658470').its('0.contentDocument.body').find('button[title="Accept cookies"]').click();

This should work if you accept the cookies.

    cy.contains('Accept', { timeout: 20000 }).click({force:true})
    Cypress.on("window:before:load", () => {
        cy.state("jQuery", Cypress.$);
    });
Related