Important: Please read the Qt Code of Conduct -

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

  • a id="mobileRegA" href="[removed]void(0);" onclick=";return false;" class="btnReg">

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

    what's wrong? thanx

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

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

  • Moderators

    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">
     QWebElement button = document.findFirst("input[type=submit]");


    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;

Log in to reply