Puppeteer - cannot switch to the iframe without an ID
I'm trying to wait for an element inside an iframe using puppeteer helper. The thing is that the iframe doesn't have an ID attribute. I tried both switchTo and within, but waitForElement() fails with timeout in both cases. It looks like switching is not happening, because I can locate elements outside the target iframe after switchTo(...). It works with webdriver and nightmare though, so the issue is with puppeteer I guess.
Has anybody encountered this issue?
Details
- CodeceptJS version: 2.0.2
- NodeJS Version: 10.13.0
- Operating System: win10
I cannot get switchTo working with Puppeteer at all (even with an id)
Details
- CodeceptJS version: v2.0.3
- Node version: v8.10.0
- Operating System: macOS mojave
Example:
I.amOnPage('/');
I.waitForElement('#myiframe');
I.switchTo('#myiframe');
I.waitForElement('h1', 5);
Output:
1) Groups
Create Group:
element (h1) still not present on page after 3 sec
waiting for selector "h1" failed: timeout 3000ms exceeded
Scenario Steps:
- I.waitForElement("h1", 5) at Test.Scenario (codecept/group_test.js:13:5)
- I.switchTo("#myiframe") at Test.Scenario (codecept/group_test.js:12:5)
- I.waitForElement("#myiframe") at Test.Scenario (codecept/group_test.js:11:5)
- I.amOnPage("/") at Test.Scenario (codecept/group_test.js:10:5)
Edit: I've also tested within with puppeteer v1.6.x and v1.11.x. docker-compose run test-acceptance.puppeteer is failing to execute tests after Session.
Session --
✔ simple session @WebDriverIO @Protractor @Puppeteer in 1573ms
✖ "after each" hook: finalize codeceptjs for "simple session @WebDriverIO @Protractor @Puppeteer" in 715ms
Error: Protocol error (Target.disposeBrowserContext): Target closed.
within --
Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
I ran into StaleElementExceptions with WebDriver, so decided to take a look at this again.
This doesn't work if you don't have names on your frames. It will never check by url. https://github.com/Codeception/CodeceptJS/blob/d28a3e0aca5f8370aa349af209928a94b6734903/lib/helper/Puppeteer.js#L1835
I think this function should look by url if it can't find anything by name.
Adding the name field to my iframe allowed me to switch between my iframe and the main page with no trouble. Before the URL of the iframe was changing behind the scenes so I could never enter into the iframe at the right time, but with name it does not matter I can call waitForElement calls again.
Please fix this issue, it is open for a long time. It is currently impossible to do any tests in an iFrame with Puppeteer. Both functions: within() and switchTo() are not working (even with an iframe id). As stated before after the switch function, it is possible to find elements outside the iFrame.
Details
- CodeceptJS version: v2.3.0
- Node version: v10.16.0
- Operating System: Windows 10
Example:
I.click('button');
I.waitForVisible('#iframe',8);
I.switchTo('#iframe');
I.waitForVisible('#element-outside-iframe', 5);
I.waitForVisible('#element-in-iframe', 5);
Output:
"before each" hook: Before for "Check velden zoekscherm":
element (#element-in-iframe) still not visible after 5 sec
waiting for selector "#element-in-iframe" failed: timeout 5000ms exceeded
I actually ran into this with a snippet like:
I.waitForElement('.mail-detail-frame');
within({ frame: '.mail-detail-frame' }, () => {
I.waitForText('This mail has no content', 3);
});
which uses I.switchTo internally. At least in my situations this patch fixes the problem.