Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Can't Find Form with WWW::Mechanize::Chrome

by xiaoyafeng (Deacon)
on May 12, 2020 at 08:08 UTC ( #11116698=perlquestion: print w/replies, xml ) Need Help??

xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

Recently I've played with awesome module W::M::C. It's very useful and easy use for me who are not very familiar with HTML/CSS. But When I use it to find login form on an our internal web page, it failed.(and can't find all the fields of the form of course) Below is the html code:

<form class="ant-form ant-form-horizontal login-form" style="left: 50% +; top: 50%;"><div class="ant-row ant-form-item"><div class="ant-col a +nt-form-item-control-wrapper"><div class="ant-form-item-control"><spa +n class="ant-form-item-children"><span class="ant-input-affix-wrapper +"><span class="ant-input-prefix"><i aria-label="icon: user" class="an +ticon anticon-user" style="color: rgba(0, 0, 0, 0.25);"><svg viewBox= +"64 64 896 896" focusable="false" class="" data-icon="user" width="1e +m" height="1em" fill="currentColor" aria-hidden="true"><path d="M858. +5 763.6a374 374 0 0 0-80.6-119.5 375.63 375.63 0 0 0-119.5-80.6c-.4-. +2-.8-.3-1.2-.5C719.5 518 760 444.7 760 362c0-137-111-248-248-248S264 +225 264 362c0 82.7 40.5 156 102.8 201.1-.4.2-.8.3-1.2.5-44.8 18.9-85 +46-119.5 80.6a375.63 375.63 0 0 0-80.6 119.5A371.7 371.7 0 0 0 136 90 +1.8a8 8 0 0 0 8 8.2h60c4.4 0 7.9-3.5 8-7.8 2-77.2 33-149.5 87.8-204.3 + 56.7-56.7 132-87.9 212.2-87.9s155.5 31.2 212.2 87.9C779 752.7 810 82 +5 812 902.2c.1 4.4 3.6 7.8 8 7.8h60a8 8 0 0 0 8-8.2c-1-47.8-10.9-94.3 +-29.5-138.2zM512 534c-45.9 0-89.1-17.9-121.6-50.4S340 407.9 340 362c0 +-45.9 17.9-89.1 50.4-121.6S466.1 190 512 190s89.1 17.9 121.6 50.4S684 + 316.1 684 362c0 45.9-17.9 89.1-50.4 121.6S557.9 534 512 534z"></path +></svg></i></span><input placeholder="Username" autocomplete="off" au +tocorrect="off" autocapitalize="off" spellcheck="false" id="username" + data-__meta="[object Object]" data-__field="[object Object]" class=" +ant-input" value=""></span></span></div></div></div><div class="ant-r +ow ant-form-item"><div class="ant-col ant-form-item-control-wrapper"> +<div class="ant-form-item-control"><span class="ant-form-item-childre +n"><span class="ant-input-password ant-input-affix-wrapper"><span cla +ss="ant-input-prefix"><i aria-label="icon: lock" class="anticon antic +on-lock" style="color: rgba(0, 0, 0, 0.25);"><svg viewBox="64 64 896 +896" focusable="false" class="" data-icon="lock" width="1em" height=" +1em" fill="currentColor" aria-hidden="true"><path d="M832 464h-68V240 +c0-70.7-57.3-128-128-128H388c-70.7 0-128 57.3-128 128v224h-68c-17.7 0 +-32 14.3-32 32v384c0 17.7 14.3 32 32 32h640c17.7 0 32-14.3 32-32V496c +0-17.7-14.3-32-32-32zM332 240c0-30.9 25.1-56 56-56h248c30.9 0 56 25.1 + 56 56v224H332V240zm460 600H232V536h560v304zM484 701v53c0 4.4 3.6 8 8 + 8h40c4.4 0 8-3.6 8-8v-53a48.01 48.01 0 1 0-56 0z"></path></svg></i>< +/span><input placeholder="Password" action="click" id="password" data +-__meta="[object Object]" data-__field="[object Object]" type="passwo +rd" class="ant-input" autocomplete="off" autocorrect="off" autocapita +lize="off" spellcheck="false" value=""><span class="ant-input-suffix" +><i aria-label="icon: eye-invisible" tabindex="-1" class="anticon ant +icon-eye-invisible ant-input-password-icon"><svg viewBox="64 64 896 8 +96" focusable="false" class="" data-icon="eye-invisible" width="1em" +height="1em" fill="currentColor" aria-hidden="true"><path d="M942.2 4 +86.2Q889.47 375.11 816.7 305l-50.88 50.88C807.31 395.53 843.45 447.4 +874.7 512 791.5 684.2 673.4 766 512 766q-72.67 0-133.87-22.38L323 798 +.75Q408 838 512 838q288.3 0 430.2-300.3a60.29 60.29 0 0 0 0-51.5zm-63 +.57-320.64L836 122.88a8 8 0 0 0-11.32 0L715.31 232.2Q624.86 186 512 1 +86q-288.3 0-430.2 300.3a60.3 60.3 0 0 0 0 51.5q56.69 119.4 136.5 191. +41L112.48 835a8 8 0 0 0 0 11.31L155.17 889a8 8 0 0 0 11.31 0l712.15-7 +12.12a8 8 0 0 0 0-11.32zM149.3 512C232.6 339.8 350.7 258 512 258c54.5 +4 0 104.13 9.36 149.12 28.39l-70.3 70.3a176 176 0 0 0-238.13 238.13l- +83.42 83.42C223.1 637.49 183.3 582.28 149.3 512zm246.7 0a112.11 112.1 +1 0 0 1 146.2-106.69L401.31 546.2A112 112 0 0 1 396 512z"></path><pat +h d="M508 624c-3.46 0-6.87-.16-10.25-.47l-52.82 52.82a176.09 176.09 0 + 0 0 227.42-227.42l-52.82 52.82c.31 3.38.47 6.79.47 10.25a111.94 111. +94 0 0 1-112 112z"></path></svg></i></span></span></span></div></div> +</div><div class="ant-row ant-form-item"><div class="ant-col ant-form +-item-control-wrapper"><div class="ant-form-item-control has-success" +><span class="ant-form-item-children"><label class="ant-checkbox-wrap +per"><span class="ant-checkbox"><input id="remember" type="checkbox" +class="ant-checkbox-input" data-__meta="[object Object]" data-__field +="[object Object]" value=""><span class="ant-checkbox-inner"></span>< +/span><span><span>Remember me</span></span></label><br><button id="lo +ginBtn" type="submit" class="ant-btn login-form-button ant-btn-primar +y"><span>Log in</span></button></span></div></div></div></form>
I found the form above has no name and id, that is the issue? but it works on browser,and obviously I can't modify the code. ;( Is there a way to find the form with W::M::C? Please enlightened me, thanks.





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

Replies are listed 'Best First'.
Re: Can't Find Form with WWW::Mechanize::Chrome
by marto (Cardinal) on May 12, 2020 at 08:17 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

      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 );
        $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');

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-09-18 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?