Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Alternative to click on this QWebElement?

Alternative to click on this QWebElement?

Scheduled Pinned Locked Moved Unsolved Qt WebKit
6 Posts 3 Posters 1.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.
  • B Offline
    B Offline
    Bob Asm2
    wrote on last edited by
    #1

    I have a html button that none of the methods I've tried before and worked does work for this one.

    The HTML (toOuterXml() output) look like this:

    "<input name="ctl00$foo" type="text" class="rcbInput radPreventDecorate rcbEmptyMessage" id="foo" value="Select something" readonly="readonly" autocomplete="off">"

    I've tried all thise to click:

    • input.evaluateJavaScript("this.click()");
    • input.evaluateJavaScript("var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);");
    • mouseClick(windowHandle(), input);

    where mouseClick is defiend as following:

    void mouseClick(QWindow *window, const QWebElement &e)
    {
        QRect pos = e.geometry();
        QPoint clickPoint(pos.x(), pos.y());
        QTest::mouseMove(window, clickPoint);
        QTest::mouseClick(window, Qt::LeftButton,
                          Qt::NoModifier, clickPoint,
                          100);
    }
    

    and input is

    auto input =
    page()
                ->mainFrame()
                ->documentElement()
                .findFirst(QString("input[id='foo']");
    

    Can someone point out the reason why it isn't workng? or provide a working alternative? I have no idea why the regular methods isn't working.

    JonBJ 1 Reply Last reply
    0
    • B Bob Asm2

      I have a html button that none of the methods I've tried before and worked does work for this one.

      The HTML (toOuterXml() output) look like this:

      "<input name="ctl00$foo" type="text" class="rcbInput radPreventDecorate rcbEmptyMessage" id="foo" value="Select something" readonly="readonly" autocomplete="off">"

      I've tried all thise to click:

      • input.evaluateJavaScript("this.click()");
      • input.evaluateJavaScript("var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);");
      • mouseClick(windowHandle(), input);

      where mouseClick is defiend as following:

      void mouseClick(QWindow *window, const QWebElement &e)
      {
          QRect pos = e.geometry();
          QPoint clickPoint(pos.x(), pos.y());
          QTest::mouseMove(window, clickPoint);
          QTest::mouseClick(window, Qt::LeftButton,
                            Qt::NoModifier, clickPoint,
                            100);
      }
      

      and input is

      auto input =
      page()
                  ->mainFrame()
                  ->documentElement()
                  .findFirst(QString("input[id='foo']");
      

      Can someone point out the reason why it isn't workng? or provide a working alternative? I have no idea why the regular methods isn't working.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Bob-Asm2
      Umm, how is <input type="text"> a "button"? It's an edit control. (It's also readonly.) What are you expecting to happen on clicking it?

      B 1 Reply Last reply
      0
      • K Offline
        K Offline
        Konstantin Tokarev
        wrote on last edited by Konstantin Tokarev
        #3

        If you just want to set focus of the element, use QWebElement::setFocus

        JonBJ 1 Reply Last reply
        0
        • K Konstantin Tokarev

          If you just want to set focus of the element, use QWebElement::setFocus

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Konstantin-Tokarev
          Since as I pointed out his element is readonly, and http://doc.qt.io/archives/qt-5.5/qwebelement.html#setFocus:

          Gives keyboard input focus to this element

          I'm not sure/would not have thought that would have much effect, for whatever the OP is trying to achieve.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bob Asm2
            wrote on last edited by
            #5

            on GUI interface, when it's clicked, a list of suggestions (a set of HTML li tags) is shown. This is what I'm trying to do programatically. I'll give a try to setFocus() but it has been unsuccefully on the past, so I've since always used evaluateJavaScript("this.focus()") instead of.

            1 Reply Last reply
            0
            • JonBJ JonB

              @Bob-Asm2
              Umm, how is <input type="text"> a "button"? It's an edit control. (It's also readonly.) What are you expecting to happen on clicking it?

              B Offline
              B Offline
              Bob Asm2
              wrote on last edited by
              #6

              @JonB What happens with that page is it seems a "hack" HTML it's of type text but on GUI appers to be a select and when you click on it it show a list of options, in form of autocompleter. I just want to click on it and display that autcompleter.

              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