Results 1 to 5 of 5

Thread: Auto login using java script

  1. #1
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Auto login using java script

    I am trying to use QWebpage to parse the data from http://www.wizards.com/dndinsider/co...r.aspx?id=3528. If the user isn't currently logged into the site it will redirect the user to a login page. If the user is redirected to the login page I want to automatically login. When I use the evaluateJavaScript call to fill in the email and password text boxes and submit the form it seems to fail to continue to the desired page. I have attached the test application I put together. Does anyone have any ideas why it wouldn't be working? The code to fill in the form and submit is the following:
    Qt Code:
    1. void Widget::on_ui_pushButtonLoad_clicked()
    2. {
    3. QWebFrame *frame = webView->page()->mainFrame();
    4. frame->evaluateJavaScript(
    5. QString( "document.getElementById('email').value = \"%1\";" ).
    6. arg( ui_lineEditName->text() ) );
    7. frame->evaluateJavaScript(
    8. QString( "document.getElementById('password').value = \"%1\";" ).
    9. arg( ui_lineEditPassword->text() ) );
    10. }
    11.  
    12. void Widget::on_ui_pushButtonSubmit_clicked()
    13. {
    14. QWebFrame *frame = webView->page()->mainFrame();
    15. frame->evaluateJavaScript( "document.forms[0].submit();" );
    16. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for the help.
    Attached Files Attached Files

  2. #2
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Auto login using java script

    So I thought it might be a cookie issue so I added a cookie jar to my QWebPage but that didn't seem to solve the issue either. If I type directly into the QwebView and click submit it works fine but when I try and use JS to fill in the email and password it doesn't work.

  3. #3
    Join Date
    May 2009
    Posts
    133
    Thanks
    10
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Auto login using java script

    I would be very interested to see solution to this problem.
    In the past I've been using
    Qt Code:
    1. QWebElement::function()
    To copy to clipboard, switch view to plain text mode 
    with "click" argument with success. This method did not become part of QWebElement API, however. Calling
    Qt Code:
    1. evaluateJavaScript
    To copy to clipboard, switch view to plain text mode 
    instead does not seem to work.

    The same question was asked here and here and here

  4. #4
    Join Date
    Jul 2009
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Auto login using java script

    actually I'm having the same problem here with 4.7.2
    from what I can say :
    - form filling and submission works by hand
    - automatic filling works, but then impossible to click manually on the submit button
    - if then I modifiy manually the fields of the form, the manual submission is OK
    - filling manually and then submit via JS also works correctly
    Thus it seems that something goes wrong when assigning the parameters of the forms. But what ? Indeed it works nicely with Firebug, so why not Webkit ?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Auto login using java script

    It all depends how the webpage is programmed to handle the form. You need to dive into the javascript that drives the form and understand what happens there. You can submit the form by calling submit() on the form or by clicking the submit button (calling click() on the button's web element). Which to choose depends on what the particular webpage does. If it substitutes the form target url when the submit button is clicked by attaching some script to the button's click event then you need to emulate the button click. If the button is disabled because there is some content validation done by the webpage, you either need to submit the form directly (using submit()) or to do something so that the button gets enabled.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Java Script on Qt4.5
    By kavinsiva in forum Newbie
    Replies: 1
    Last Post: 7th October 2009, 13:08

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.