iframe内的Web元素的QuerySelector [英] QuerySelector for Web Elements Inside iframe
问题描述
编辑:新标题。
我正在寻找的是iframe中元素的document.querySelector。
New title. What I'm looking for is a document.querySelector for elements inside an iframe.
我已经做了很多谷歌搜索,最后我很难过。
I've done quite a bit of Googling for an answer and finally I'm stumped.
我正在尝试在iframe内部进行查询。我正在构建在Selenium中使用的字符串选择器,通常我只是用Firebug检查元素,并使用document.querySelectorAll(theStringIBuid);
I'm trying to query inside an iframe. I'm building string selectors to be used in Selenium and usually I just inspect the element with Firebug, and use document.querySelectorAll("theStringIBuid");
但它没有使用iframe中的元素。我已经尝试了以下所有内容在page-iframeiframe中获取元素radiobutton1。
But it doesn't work with elements inside iframes. I've tried all of the below to get an element "radiobutton1" inside the "page-iframe" iframe.
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
谢谢 -
推荐答案
简单的es6改编自 h3manth :
document.querySelectorAll('iframe').forEach( item =>
console.log(item.contentWindow.document.body.querySelectorAll('a'))
)
这篇关于iframe内的Web元素的QuerySelector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!