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. In QWebKit , how can I clicked the web html's button by program?
Qt 6.11 is out! See what's new in the release blog

In QWebKit , how can I clicked the web html's button by program?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.1k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    stabber
    wrote on last edited by
    #1

    a id="mobileRegA" href="[removed]void(0);" onclick="_Global.mobile.start();return false;" class="btnReg">
    Register

    [removed]void(0) ==》 avascript:void(0);
    here's code snippet ,
    @
    QWebFrame *frame = ui.webView->page()->mainFrame();
    QWebElement mainRegA = frame->findFirstElement("#mainRegA");
    mainRegA.evaluateJavaScript("this.clicked");
    @

    what's wrong? thanx

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kurt.pattyn
      wrote on last edited by
      #2

      Just use ...evaluateJavaScript("document.getElementById("mainRegA").clicked()

      Also you are searching for #mainRegA (name includes #).

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

        taken from the QWebElement docs:
        @
        QWebElement document = frame->documentElement();
        /* Assume that the document has the following structure:

             <form name="myform" action="submit_form.asp" method="get">
                 <input type="text" name="myfield">
                 <input type="submit" value="Submit">
             </form>
        
          */
        
         QWebElement button = document.findFirst("input[type=submit]");
         button.evaluateJavaScript("this.click()");
        

        @

        Compare this with your code: the problem is that a-Elements don't support the click() method (only input-Elements).
        Are you using jQuery? AFAIK jQuery would provide an click() method for a-Elements.
        If not you need to do something like this:
        @
        var href = document.getElementById("mainRegA").getAttribute('href');
        [removed].href = href;
        @

        --- 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

        • Login

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