Clicking buttons inside an iframe fails in headless Chrome only
See original GitHub issueCurrent behavior:
Play/Pause buttons inside of the body of an embedded Youtube video on a webpage (in an iframe) are not found in headless Chrome 79 and test is failing. The same test passes in headless Electron 78 as well as headed Chrome 79 and headed Canary 81.
CypressError: Timed out retrying: Expected to find element: 'button[aria-label="Play"]', but never found it. Queried from element: <body.date-20200113.de_DE.ltr.exp-invert-logo.exp-kevlar-settings.exp-responsive.exp-search-big-thumbs.site-center-aligned.site-as-giant-card.webkit.webkit-537>
Desired behavior:
I know iframes are a bit of a murky area with Cypress, I just cannot figure out why there is a difference and the same test fails only in headless Chrome. Ideally the desired behavior would be the Play/Pause buttons to be found inside of the Youtube iframe body in headless Chrome.
Test code to reproduce
cy.visit('https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell')
cy.get('iframe[title="youtube video"]').then(($iframe) => {
const $body = $iframe.contents().find('body')
cy.wrap($body).find('button[aria-label="Play"]').click()
cy.wrap($body).find('button[aria-label="Pause (k)"]').click()
})
Versions
Cypress 3.8.1, Windows 10, headless Chrome 79
Screenshots
Failed test in headless Chrome 79:
Passed test in headless Electron 78:
Passed test in headed Chrome 79:
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Unable to locate elements on webpage with headless chrome
have the headless browser take a screenshot. · 1 · Okay so I've found that the webpage isn't loading properly, and ends up...
Read more >Issue 2198: ChromeDriver 2.34 doesn't wait until iframe ...
the only workaround is to wait X seconds between the switchTo() and any actual command inside the Iframe, or downgrade Chrome & chromedriver....
Read more >iFrames in Selenium WebDriver - Tools QA
Selenium can only access the elements in a specific context, and the context of the main web page and the embedded iframe are...
Read more >Puppeteer documentation - DevDocs
Puppeteer 7.1.0 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
Read more >Chrome Enterprise and Education release notes
From Chrome on iOS 108, it is easier for users to access their passwords. We have simplified the password list view, to show...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@allwefly No worries, it’s not the first time I’ve seen locale differences with tests.
It’s usually good practice to set one in your tests. You can also set timezone for datetime variations as a machine environment variable like
TZ=America/New_York cypress run
.Well , i know this issue closed but i got the same error like you got at first time @jennifer-shehane
I have set “chromeWebSecurity” as false and have same code like allwefly Can you please tell me what i missed ?
cypress: 4.10.0