编辑:新标题。 我在寻找的是iframe中的元素的document.querySelector。iframe中的Web元素的QuerySelector
我已经做了相当多的谷歌搜索答案,最后我很难过。
我想在iframe中查询。我正在构建Selenium中使用的字符串选择器,通常我只是用Firebug检查元素,并使用document.querySelectorAll(“theStringIBuid”);
但它不适用于iframe中的元素。我已经尝试了下面的所有内容以在“page-iframe”iframe中获取元素“radiobutton1”。
var elem1 = ".page-iframe";
console.log(elem1);
var elem2 = ".radiobutton1";
console.log(elem2);
document.querySelectorAll(elem1+elem2+"");
document.querySelectorAll('.page-iframe').contentWindow.document.body.querySelectorAll('.radiobutton1')
document.getElementById('.page-iframe').contentWindow.document.body.innerHTML;
[].forEach.call(document.querySelectorAll('.page-iframe'),
function fn(elem){
console.log(elem.contentWindow.document.body.querySelectorAll('.radiobutton1')); });
var contentWindow = document.getElementById('.page-iframe').contentWindow
var contentWindow = document.querySelectorAll('.page-iframe')
var contentWindow = document.querySelectorAll('.page-iframe')[0].contentWindow
Thanks-
你或许运行脚本完成的iframe装载之前?如果你console.log contentWindow,你会得到什么? – Spokey 2014-10-29 12:38:43
如果你使用硒,你需要调用switchTo().frame(“frame of id”)然后运行你的代码。 – bcar 2014-10-29 12:52:38
嗯,我一直在这个工作了两个小时,所以我认为该页面已完成加载:) – snug 2014-10-30 08:31:27