admin管理员组文章数量:1302243
I want to select a nested iframe within an iframe with the selenium webdriver module in node-js.
For example:
<iframe id="firstframe">
<div id="firstdiv"></div>
<iframe id="secondframe">
<div id="seconddiv"></div>
</iframe>
</iframe>
for the node-js part:
driver.switchTo().defaultContent();
driver.switchTo().frame("firstframe"); // --> works
driver.switchTo().frame("secondframe"); // --> NoSuchFrameError
iframes = driver.findElements(webdriver.By.tagName('iframe')).then(function(elements){
console.log(elements.length); // --> if I put this code before the switch to first frame output: 1, if I put it after output: 0)
});
I tried using the index number but this also failed.
Edit:
Ok, I figured it out but my answer got deleted by user @casparOne for some reason. If anyone still wonders what the problem was here goes:
My code above works, just not locally. Chrome's security settings refuse to go deeper in an iframe on a local file. Hence it didn't even show the source code for the iframe.
I want to select a nested iframe within an iframe with the selenium webdriver module in node-js.
For example:
<iframe id="firstframe">
<div id="firstdiv"></div>
<iframe id="secondframe">
<div id="seconddiv"></div>
</iframe>
</iframe>
for the node-js part:
driver.switchTo().defaultContent();
driver.switchTo().frame("firstframe"); // --> works
driver.switchTo().frame("secondframe"); // --> NoSuchFrameError
iframes = driver.findElements(webdriver.By.tagName('iframe')).then(function(elements){
console.log(elements.length); // --> if I put this code before the switch to first frame output: 1, if I put it after output: 0)
});
I tried using the index number but this also failed.
Edit:
Ok, I figured it out but my answer got deleted by user @casparOne for some reason. If anyone still wonders what the problem was here goes:
My code above works, just not locally. Chrome's security settings refuse to go deeper in an iframe on a local file. Hence it didn't even show the source code for the iframe.
Share Improve this question edited Dec 6, 2013 at 16:19 F. Rakes asked Dec 5, 2013 at 13:33 F. RakesF. Rakes 1,5373 gold badges17 silver badges25 bronze badges 3-
Before switching to the
secondframe
try to switch back to default content. – Furious Duck Commented Dec 5, 2013 at 15:24 -
Getting a
NoSuchFrameError
as well. – F. Rakes Commented Dec 5, 2013 at 15:32 - you can use driver.switchTo().frame("secondframe"); – rüff0 Commented Sep 8, 2023 at 4:25
2 Answers
Reset to default 5I've done this kind of thing before a few times. Try putting a 1 second pause between the swtich frames. (Sometimes) you need to give Selenium (or the browser) enough time for the frame DOM to load before you try another switch.
You can use
driver.switchTo().frame(0);
instead of
driver.switchTo().frame("secondframe");
, as it is the sole child iframe within the parent.
本文标签: nodejsSelecting nested iframeseleniumjavascriptnodejsStack Overflow
版权声明:本文标题:node.js - Selecting nested iframe - seleniumjavascriptnode-js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741669588a2391521.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论