JavaScript to automate a submiting a form

问题: I am trying to automate the login of a web page using vanilla JavaScript. This is the form on the web page: <form id="tbb_logon_form" class="login_form" method="post...

问题:

I am trying to automate the login of a web page using vanilla JavaScript.

This is the form on the web page:

<form id="tbb_logon_form" class="login_form" method="post" action="https://www.btopenzone.com:8443/tbbLogon" name="login_form">
    <fieldset class="username-field">
        <label for="email" id="lbl-email">BT ID</label>
        <input type="text" id="username" name="username" class="required" tabindex="3" value="username" placeholder="This is usually your email address">
    </fieldset>
    <fieldset>
        <label for="password">Password</label>
        <input type="password" id="password" name="password" class="required" value="password" tabindex="4">
    </fieldset>
    <input type="submit" value="Login" id="lgnbtn" tabindex="5" id="loginbtn" onclick="var s=s_gi('btiopenzone'); s.linkTrackVars='eVar19,prop50'; s.eVar19='OZ|Home Hub|Landing Page|Account selected:BT Broadband'; s.prop50='OZ|Home Hub|Landing Page|Account selected:BT Broadband'; s.tl(this,'o','OZ|Home Hub|Landing Page|Account selected:BT Broadband');">
    <input name="xhtmlLogon" type="hidden" value="https://www.btopenzone.com:8443/tbbLogon">
</form>

The things have tried are:

document.getElementById("lgnbtn").submit();
document.getElementById("lgnbtn").click();

but neither are automating the click of the login button. Please help me.


回答1:

You can submit your form using:

document.forms[0].submit();

or

document.forms["login_form"].submit();
  • 发表于 2019-03-01 19:01
  • 阅读 ( 182 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除