Jump to content

Hello, I have this VBScript here. It's made to login on a website (School site, they have made it a pain in the ass to login beacuse it's like several different pages and tons of usless buttons to click to get there)

I've gotten the script to work as I want but the problem is that it opens in IE. I know Chrome doesn't support VBScripts but I've read some about tricking it to use it. Or is there another good way to create a script to do all this script does. (Most important is I don't want to use any "Sleep" because the main reason is to get the fastest login time the connection can handle, and as that varies it's hard to use any timings)

Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "http://google.com"
Do
    WScript.Sleep 500
loop While IE.ReadyState < 4 And IE.Busy 
IE.Document.getElementByID("username").value = "user"
IE.Document.getElementByID("password").value = "pass"
IE.Document.getElementByID("Submit1").Click

WScript.Sleep 5000

Dim LinkHref
Dim a

LinkHref = "link"

For Each a In IE.Document.GetElementsByTagName("a")
  If LCase(a.GetAttribute("href")) = LCase(LinkHref) Then
    a.Click
    Exit For  ''# to stop after the first hit
  End If
Next

 

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
https://linustechtips.com/topic/558954-vbscript-problems/
Share on other sites

Link to post
Share on other sites

Not sure about VBScript but you could create a bookmark with javascript that did what you wanted, unsure of what your foreach loop is supposed to do at the bottom but the first part of the code is super easy

 

window.location.href = "http://www.google.com";
while (document.readyState !== "complete");
document.getElementById("username").value = "user";
document.getElementById("password").value = "pass";
document.getElementByID("Submit1").Click();

 

Link to comment
https://linustechtips.com/topic/558954-vbscript-problems/#findComment-7355055
Share on other sites

Link to post
Share on other sites

2 hours ago, MSVSora said:

Not sure about VBScript but you could create a bookmark with javascript that did what you wanted, unsure of what your foreach loop is supposed to do at the bottom but the first part of the code is super easy

 


window.location.href = "http://www.google.com";
while (document.readyState !== "complete");
document.getElementById("username").value = "user";
document.getElementById("password").value = "pass";
document.getElementByID("Submit1").Click();

 

I've probably just messed up the loops at the bottom (I'm very new to VBScript so it has been alot lf trial and error coding) but what if the code I have under the first part? That one is intended for another page that loads where it searches for a link. Will I have to load a new script for that site or can I make the first one continue to the new page with similar form filling/button clicking code? 

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
https://linustechtips.com/topic/558954-vbscript-problems/#findComment-7355832
Share on other sites

Link to post
Share on other sites

1. Chrome doesn't support VBScript:

You're right, but it doesn't support VBScript running inside of a webpage... the script you have is running outside of the browser and by the Operating System instead, so modifying the CreateObject line might work depending how Chrome's built & what it's API exposes (i.e. I've never checked if there's Chrome.Application or similar you can pop in there myself).

 

2. Another way of performing that same workload:

Yes, you have a few options. A test automation tool such as Selenium (free) or a client process automation tool like AutoHotKey (also free?) will work too. For the most part, what's suggested above with bookmarking the page in your browser and asking the browser to save the logon credentials will make all of that script apart from 1x last link click, obsolete.

 

3. Alternative to sleep

Here you're using a scripting language and realistically the only way to interact with the browser's state is via that IE object's properties. IMO if you're using this script, you need the waits, but (i) can keep the increment counter to something low like 500 and stick it inside of a loop like you're doing with the top wait instance "loop While IE.ReadyState < 4 And IE.Busy" - this will lead to the script and potentially the OS being unresponsive until the browser page has refreshed and the page content has loaded (depending on the value passed in https://msdn.microsoft.com/en-us/library/ms534361%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396).

 

If you went the TA tool way, Selenium has assertions (other tools have what's known as chekpoints) which let you write loops which say "whilst the string 'welcome, logged in user Alex' hasn't yet appeared on the page, wait".
 

4. What does the bottom loop do:

It searches for a link in the format <a href="link">SomeTextHere</a> (where I'm guessing the proper value of the "link" part has been stripped out for this web posting). When that link is found, it's clicked on and the loop exits. Basically it's performing a search and click on a single hyperlink inside of the 2 webpage (that presented after the login).

Link to comment
https://linustechtips.com/topic/558954-vbscript-problems/#findComment-7359251
Share on other sites

Link to post
Share on other sites

window.location.href = "http://www.google.com";
while (document.readyState !== "complete");
document.getElementById("username").value = "user";
document.getElementById("password").value = "pass";
document.getElementByID("Submit1").Click();
LinkHref = "http://www.google.com";
while (document.readyState !== "complete");
var elements = document.getElementsByTagName("a");
for(var i = 0; i < elements.length; i++)
{
    if(elements[i].getAttribute("href").toLowerCase() == LinkHref.toLowerCase())
    {
        elements[i].click()
        break;
    }
}

So basically @xQubeZx add this as a bookmark (just replace the LinkHref, username and password, window.location.href values) 

 

javascript:window.location.href = "http://www.google.com"; while (document.readyState !== "complete"); document.getElementById("username").value = "user"; document.getElementById("password").value = "pass"; document.getElementByID("Submit1").Click(); LinkHref = "http://www.google.com"; while (document.readyState !== "complete"); var elements = document.getElementsByTagName("a"); for(var i = 0; i < elements.length; i++){ if(elements.getAttribute("href").toLowerCase() == LinkHref.toLowerCase()){elements.click()}}

 

Edit: fixed a couple of bugs

Link to comment
https://linustechtips.com/topic/558954-vbscript-problems/#findComment-7360199
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×