PDA

View Full Version : Setting attribute in webpage and press button ‘GO’



sujan.dasmahapatra
21st June 2013, 09:27
I am developing a web application. I need to select an option from dropdown in a website and press ‘GO’ button.

I am connect with the website like as below.

QNetworkAccessManager *m_manager = new QNetworkAccessManager(this);
connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
m_manager->get(QNetworkRequest(QUrl("http://www.mysite.com/")));

m_WebPage = new QWebPage();
m_WebPage->setNetworkAccessManager(m_manager);
QString attr = m_WebPage->mainFrame()->documentElement().setAttribute("Diablo 3 (Diablo III)", "MySelection");
but with this my application crashing. Please tell me how can set an attribute in a webpage and press go. How can I get the attribute and the button ‘GO’ in my application.

Any suggestions is highly appreciated. Thanks Sujan

ChrisW67
22nd June 2013, 01:08
This line makes no sense and does not compile:


QString attr = m_WebPage->mainFrame()->documentElement().setAttribute("Diablo 3 (Diablo III)", "MySelection");
setAttribute() does not return a value (it's void). In any case, you are trying to set an attribute on a default, empty HTML document because you have not loaded anything into your QWebPage.

If you want to drive the web page as if a user were doing it then you need to:

load the web page into the QWebPage,
wait until loadFinished(),
locate the element representing the drop down list
change its value
locate the element representing the submit button, and
fake clicking it.

sujan.dasmahapatra
22nd June 2013, 11:10
how can I find an element for the drop down menu in webpage.

sujan.dasmahapatra
22nd June 2013, 13:45
To select 2 options I do the following. And also click. But the values in my QWebView are not changing based on this. Please help whats wrong going on.

QWebElement selectBox =
m_WebView->page()->mainFrame()->findFirstElement("select[id=gameid]");

selectBox.setAttribute("value", "187");

QWebElement selectBox2 =
m_WebView->page()->mainFrame()->findFirstElement("select[id=hostid]");

selectBox2.setAttribute("value", "24351");


QWebElement button = m_WebView->page()->mainFrame()->documentElement().findFirst("input[type=button]");
button.evaluateJavaScript("this.click()");