in reply to Can't Find Form with WWW::Mechanize::Chrome

$mech->form_number 'Selects the numberth form.'.

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

Replies are listed 'Best First'.
Re^2: Can't Find Form with WWW::Mechanize::Chrome
by xiaoyafeng (Deacon) on May 12, 2020 at 09:05 UTC
    Many Thanks! it works! @@




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

Re^2: Can't Find Form with WWW::Mechanize::Chrome
by Anonymous Monk on May 12, 2020 at 09:20 UTC
    Sorry I ask another stupid question on this node. As your help, I can find the form But it still can't submit and login! Actually, I can see the chrome open, username&password input but no login
    use WWW::Mechanize::Chrome; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ER +ROR my $mech = WWW::Mechanize::Chrome->new(); $mech->get('http://10.86.11.200:8090/'); $mech->form_number(1); $mech->field('#username', 'admin'); $mech->field('#password', '*******'); $mech->click_button(id => 'loginBtn'); sleep 10;
    Is there any other mistake I don't notice? Please Help
      $mech->click_button(id => 'loginBtn');

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

      my $btn = $mech->xpath('//*[@id="loginBtn"]', single => 1 ); print $btn->get_attribute('outerHTML'); $mech->click( $btn );

        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!

      $mech->click_button(id => 'loginBtn');

      Untested, should the id be prefixed with #? 'A selector prefixed with '#' must match the id attribute of the input'.

      $mech->click_button(id => '#loginBtn');