Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Clicking a button on a web page programmatically with QtWebkit

Clicking a button on a web page programmatically with QtWebkit

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I have a page with this weird button: http://i49.fastpic.ru/big/2013/0730/18/e6fab472339b1d91801641f73a6af418.jpg

    (that's the whole button, I didn't cut anything out).

    I have managed to find it on the page (or so I believe) with this code:
    @QWebElementCollection buttons = _webView->page()->mainFrame()->findAllElements("button[onclick="send.comment(this);"]");
    QWebElement button = buttons.at(0);@

    There's only 1 element in buttons, so I assume this is it. What I previously did for clicking buttons is:

    @button.evaluateJavaScript("this.click()");@

    And it worked on other pages with other buttons, but with this button it doesn't. I've also tried

    @button.evaluateJavaScript("send.comment(this);");@

    To no avail as well. How to do it?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Violet Giraffe
      wrote on last edited by
      #2

      Also tried sending artificial mouse clicks. Doesn't work either, but I wonder if I'm doing something wrong here:

      @QPoint globalPos = _webView->mapToGlobal(button.geometry().topLeft() + QPoint(5, 5));

      QApplication::postEvent(_webView, new QMouseEvent(QEvent::MouseButtonPress, globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));

      QApplication::postEvent(_webView, new QMouseEvent(QEvent::MouseButtonRelease, globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));@

      Interesting thing here is that QApplication::widgetAt(globalPos) returns null. Also, globalPos is outside of my screen (because the web page is pretty long).

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        if your that's really your button declaration and nothing else you've posted, how should button[onclick="send.comment(this);"]" work? It doesn't have a "onclick" attribute specified.
        Do you load an external site or html which is generated by you?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Violet Giraffe
          wrote on last edited by
          #4

          I think the forum engine has eaten some code. Fixed, thanks for pointing out.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by
            #5

            Any ideas?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved