选择嵌套的iframe - selenium / javascript / node-js [英] Selecting nested iframe - selenium / javascript / node-js
问题描述
我想在node-js中使用selenium webdriver模块在iframe中选择嵌套的iframe。
I want to select a nested iframe within an iframe with the selenium webdriver module in node-js.
例如:
<iframe id="firstframe">
<div id="firstdiv"></div>
<iframe id="secondframe">
<div id="seconddiv"></div>
</iframe>
</iframe>
节点-js部分的
:
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.
编辑:
好的,我想出来但我的答案被用户@casparOne因某些原因删除了。如果有人仍然想知道这里的问题是什么:
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:
上面的代码工作,只是不在本地。 Chrome的安全设置拒绝在本地文件的iframe中更深入。因此它甚至没有显示iframe的源代码。
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.
推荐答案
我之前做过这样的事情。倍。尝试在swtich帧之间暂停1秒钟。 (有时候)你需要给Selenium(或浏览器)足够的时间来加载帧DOM,然后再尝试另一个开关。
I'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.
这篇关于选择嵌套的iframe - selenium / javascript / node-js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!