Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: Can't Find Form with WWW::Mechanize::Chrome

by Anonymous Monk
on May 13, 2020 at 01:56 UTC ( [id://11116734]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Can't Find Form with WWW::Mechanize::Chrome
in thread Can't Find Form with WWW::Mechanize::Chrome

The above should work, but you can check whether the correct element is used by inspecting it:

Thanks your help, it can find the correct element, but it doesn't login by the script. I notice that when if I comment the lines about click, I can see the input content(admin, **** ) on the chrome, but when I submit thru the $mech->click_button(id => 'loginBtn'), the contents in the form will disappear!. that's why I can't login I think.

Sorry for my poor HTML knowledge, I can't understand what happen behind this situation. Please help!

  • Comment on Re^4: Can't Find Form with WWW::Mechanize::Chrome

Replies are listed 'Best First'.
Re^5: Can't Find Form with WWW::Mechanize::Chrome
by Corion (Patriarch) on May 13, 2020 at 06:15 UTC

    Without seeing the Javascript and the complete page, I can only guess and suggest to use the heavy mallet instead:

    Maybe the form fields are just there for show and the Javascript on the page copies the contents of the form fields as they are entered into some JS variables.

    One approach would be to make WWW::Mechanize::Chrome send the appropriate control events in the hope that the Javascript picks them up:

    my @pre_events = (qw(focus)); my @post_events = (qw(blur)); $mech->field('#username', 'admin', undef, \@pre_events, \@post_events) +; $mech->field('#password', '*******', undef, \@pre_events, \@post_event +s); $mech->click_button(id => 'loginBtn');

    Another possible approach then would be to use the ->sendkeys to "enter" the data into the form fields:

    $mech->eval('document.getElementById("username").focus()'); $mech->sendkey(string => 'admin'); $mech->eval('document.getElementById("password").focus()'); $mech->sendkeys(string => '*******'); $mech->click_button(id => 'loginBtn');
      Thanks, the later way works. And for a html newbie like me, it's really straightforward and easy to understand.




      I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116734]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found