fix(webdriverio): fix iframe switch not working in some commands#13721
fix(webdriverio): fix iframe switch not working in some commands#13721NearHuscarl wants to merge 1 commit intowebdriverio:mainfrom
Conversation
|
| await browser.switchToFrame(iframe) | ||
| } | ||
| async function setAttribute(selector: string, attributeName: string, attributeValue: string) { | ||
| await browser.execute((elementSelector, attributeName, attributeValue) => { |
There was a problem hiding this comment.
Would be easier to used elem.execute here so you already have the element reference as in v9 the execute method also exists on the Element object
|
Hi @NearHuscarl thank you for looking into these issues and providing a PR. Could you sign the CLA please? 🙂 |
christian-bromann
left a comment
There was a problem hiding this comment.
I don't think this goes into the right direction as it patches the current flaw of WebdriverIO of not being able to control into which frame the user is moving. I have a different proposal here: #13728
|
@christian-bromann Unfortunately it doesn't work for my case, I have 2 different iframes where the contents are set via <html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<h1>Hello there!</h1>
<iframe
id="my-iframe"
srcdoc=""
style="border: none; width: 100%; height: 100%"
></iframe>
<iframe
id="my-iframe-2"
srcdoc=""
style="border: none; width: 100%; height: 100%"
></iframe>
<script>
window.onload = () => {
const setFrameContent = (iframeId, htmlContent) => {
const iframe = document.getElementById(iframeId);
iframe.srcdoc = htmlContent;
};
setFrameContent(
'my-iframe',
`
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<h2>Hello from iframe</h2>
</body>
</html>
`
);
setFrameContent(
'my-iframe-2',
`
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<h2>Hello from iframe 2</h2>
</body>
</html>
`
);
};
</script>
</body>
</html>const tree = await browser.browsingContextGetTree({ maxDepth: 10 });
console.log(JSON.stringify(tree, null, 2)); |
I have refined the implementation to support this use case. I will introduce a new command called await browser.url('https://the-internet.herokuapp.com/nested_frames')
await browser.switchFrame(() => browser.$('aria/MIDDLE').isExisting())
console.log((await browser.$('body').getHTML()).trim())
await browser.switchFrame(() => browser.$('aria/BOTTOM').isExisting())
console.log((await browser.$('body').getHTML()).trim())
await browser.switchFrame(() => browser.$('aria/RIGHT').isExisting())
console.log((await browser.$('body').getHTML()).trim())I will go ahead and close this PR in favor of #13728, thanks for your feedback. |
Proposed changes
Fix #13218, #13384
Note: the tests for the fix are kinda awkward as I don't think I have access to the
guinea-pig.webdriver.iodomain.Related PR: #13659
Types of changes
Checklist
Backport Request
//: # (The current
mainbranch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against thev8branch.)v9and doesn't need to be back-ported#XXXXXFurther comments
Reviewers: @webdriverio/project-committers