Results 1 to 4 of 4

Thread: Setting attribute in webpage and press button ‘GO’

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Smile Setting attribute in webpage and press button ‘GO’

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Setting attribute in webpage and press button ‘GO’

    This line makes no sense and does not compile:
    Qt Code:
    1. QString attr = m_WebPage->mainFrame()->documentElement().setAttribute("Diablo 3 (Diablo III)", "MySelection");
    To copy to clipboard, switch view to plain text mode 
    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.

  3. #3
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: Setting attribute in webpage and press button ‘GO’

    how can I find an element for the drop down menu in webpage.

  4. #4
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: Setting attribute in webpage and press button ‘GO’

    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()");

Similar Threads

  1. I press a button and receive 2 pressed() signals
    By JuanMO in forum Qt Programming
    Replies: 4
    Last Post: 21st November 2010, 06:58
  2. Replies: 2
    Last Post: 17th September 2010, 11:44
  3. Replies: 6
    Last Post: 21st August 2010, 21:09
  4. Replies: 1
    Last Post: 17th May 2010, 16:15
  5. Replies: 2
    Last Post: 10th November 2009, 06:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.