#include <QApplication>
#include <QUrl>
#include <qwebview.h>
#include <qwebframe.h>
#include <qwebelement.h>
static QWebFrame *frame;
static void traverse()
{
frame->setHtml("<html><body><p>First Paragraph</p><p>Second Paragraph</p></body></html>");
QWebElement doc = frame->documentElement();
QWebElement body = doc.firstChild();
QWebElement firstParagraph = body.firstChild();
QWebElement secondParagraph = firstParagraph.nextSibling();
}
static void findButtonAndClick()
{
frame->setHtml("<form name=\"myform\" action=\"submit_form.asp\" method=\"get\">"
"<input type=\"text\" name=\"myfield\">"
"<input type=\"submit\" value=\"Submit\">"
"</form>");
QWebElement document = frame->documentElement();
QWebElement button = document.findFirst("input[type=submit]");
button.evaluateJavaScript("click()");
}
static void autocomplete1()
{
QWebElement document = frame->documentElement();
QWebElement firstTextInput = document.findFirst("input[type=text]");
QString storedText = firstTextInput.attribute("value");
}
static void autocomplete2()
{
QWebElement document = frame->documentElement();
QString storedText = "text";
QWebElement firstTextInput = document.findFirst("input[type=text]");
textInput.setAttribute("value", storedText);
}
static void findAll()
{
QWebElement document = frame->documentElement();
QWebElementCollection allSpans = document.findAll("span");
QWebElementCollection introSpans = document.findAll("p.intro span");
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWebView *view = new QWebView(0);
frame = view->page()->mainFrame();
traverse();
findAll();
findButtonAndClick();
autocomplete1();
autocomplete2();
return 0;
}