简体   繁体   中英

How to automate a login to a website with VBS

At my office, there is an online documents viewing system which requires a login. I was thinking about automating this with VBS, and came around to the following:

 Call Main Function Main Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_") IE.Visible = True IE.Navigate "***WEBSITE CENSORED***" Wait IE With IE.Document .getElementByID("username").value = "USERNAME" .getElementByID("password").value = "PASSWORD" .getElementByID("loginbtn")(0).Submit End With End Function Sub Wait(IE) Do WScript.Sleep 500 Loop While IE.ReadyState < 4 And IE.Busy End Sub 

In theory, this should work ( I think), but it isn't.
Where am i going wrong?

EDIT: The following is the login form from my website. For safety reasons, i have linked it to example.com.

 <form id="login" action="http://example.com/login/index.php" method="post"> <div class="loginform"> <div class="form-label"><label for="username">Username</label></div> <div class="form-input"> <input name="username" id="username" type="text" size="15" value=""> </div> <div class="clearer"> <!-- --> </div> <div class="form-label"><label for="password">Password</label></div> <div class="form-input"> <input name="password" id="password" type="password" size="15" value=""> </div> </div> <div class="clearer"> <!-- --> </div> <div class="rememberpass"> <input name="rememberusername" id="rememberusername" type="checkbox" value="1"> <label for="rememberusername">Remember username</label> </div> <div class="clearer"> <!-- --> </div> <input id="loginbtn" type="submit" value="Log in"> <div class="forgetpass"><a href="forgot_password.php">Forgotten your username or password?</a></div> </form> 

Thanks to @SearchAndResQ for the answer.

Needed to change

.getElementByID("loginbtn")(0).Submit

to

.getElementByID("loginbtn").click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM