我有一個簡單的使用QtWebkit的Qt GUI應用程序。我正在使用大量嵌套的IFRAME標籤加載複雜頁面。我想遍歷完整的DOM樹(如Chrome瀏覽器在調試面板中執行的操作),其中包括iframe的內容。如何獲取iframe/frame QWebElement的QWebFrame?
我的代碼是:
QWebElement doc = ui->webView->page()->mainFrame()->documentElement();
QWebElement iframe = doc.findFirst("iframe[id=someid]");
QWebFrame *webFrame = ....? // how to get the QWebFrame for an iframe/frame QWebElement?
注: 我可以遍歷在所有幀(包括嵌套):
void MainWindow::renderFramesTree(QWebFrame *frame, int indent)
{
QString s;
s.fill(' ', indent * 4);
ui->textLog->appendPlainText(s + " " + frame->frameName());
foreach (QWebFrame *child, frame->childFrames())
renderFramesTree(child, indent + 1);
}
但我的問題是不是有關。我需要獲得iframe-QWebElement的相應QWebFrame *。
Thanx!
是的,這是很好的解決方案,但前提是你知道的名字或
我對此使用了3個因素:名稱或標識,幾何和源URL。您可以比較幀和webelement的幾何體,src屬性和幀的URL。但即便如此,在極少數情況下,我無法將幀樹匹配到iframe節點,但非常不常見 – varela