Please check the code snippet below. I am trying to click on link in the page twice and then a table is loaded i want to read one data from the table from 1st row and 2nd column. Please help.
void MainWindow::LoadFinishedCB(bool ok)
{
return;
button_click = m_WebView->page()->mainFrame()->documentElement().findAll("a");
qDebug() << button_click.count() << "\n";
button_click.at(5).evaluateJavaScript(
"var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);"
);
button_click.at(48).evaluateJavaScript(
"var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);"
);
//The above piece loads a new link in the same page.
//At this stage how can I make the program to wait till the page is //refreshed ???
out << m_WebView->page()->currentFrame()->toHtml() << "\n";
QWebElementCollection tables = m_WebView->page()->currentFrame()->findAllElements("table [id=layer_showhost]");
qDebug() << tables.count() << "\n";
QWebElementCollection trs = tables.first().document().findAll("tr");
qDebug() << trs.count() << "\n";
for(int m=0; m<trs.count(); m++)
{
QWebElementCollection tds = trs.at(m).document().findAll("td");
qDebug() << tds.count() << "\n";
for(int n=0; n<tds.count(); n++)
{
QWebElementCollection spans = tds.at(n).document().findAll("span");
qDebug() << spans.count() << "\n";
for(int z=0; z<spans.count(); z++)
{
out << spans.at(z).document().toPlainText() << " ";
}
}
}
}
void MainWindow::LoadFinishedCB(bool ok)
{
QFile file("out.txt");
if (!file.open(QIODevice::WriteOnly))
return;
QTextStream out(&file);
button_click = m_WebView->page()->mainFrame()->documentElement().findAll("a");
qDebug() << button_click.count() << "\n";
button_click.at(5).evaluateJavaScript(
"var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);"
);
button_click.at(48).evaluateJavaScript(
"var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);"
);
//The above piece loads a new link in the same page.
//At this stage how can I make the program to wait till the page is //refreshed ???
out << m_WebView->page()->currentFrame()->toHtml() << "\n";
QWebElementCollection tables = m_WebView->page()->currentFrame()->findAllElements("table [id=layer_showhost]");
qDebug() << tables.count() << "\n";
QWebElementCollection trs = tables.first().document().findAll("tr");
qDebug() << trs.count() << "\n";
for(int m=0; m<trs.count(); m++)
{
QWebElementCollection tds = trs.at(m).document().findAll("td");
qDebug() << tds.count() << "\n";
for(int n=0; n<tds.count(); n++)
{
QWebElementCollection spans = tds.at(n).document().findAll("span");
qDebug() << spans.count() << "\n";
for(int z=0; z<spans.count(); z++)
{
out << spans.at(z).document().toPlainText() << " ";
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks