views:

141

answers:

1

Hi, guys. Here's another sample script in VBScript. It opens internet explorer, navigates to google, sets up a search field and submits a query.

set ie = CreateObject("InternetExplorer.Application")

ie.navigate("www.google.com")

ie.visible = true

while ie.readystate <> 4
    wscript.sleep 100
WEnd

set fields = ie.document.getelementsbyname("q")
set buttons = ie.document.getelementsbyname("btnG")

fields(0).value = "some query"
buttons(0).click

Everything goes o.k.

And here is a script in JScript, that is supposed to do the very same thing:

var ie = new ActiveXObject("InternetExplorer.Application");

ie.visible = true;
ie.navigate("www.google.com");

do {
    WScript.Sleep(100); 
} while (ie.readystate !== 4);

var input = ie.document.getElementsByName("q");
var button = ie.document.getElementsByName("btnG");

input(0).value = "some query";  
button(0).click;

It sets up search field to "some query" correctly, but it doesn't click the button! Literally, nothing happens after input(0).value = "some query"; line.

I'm new to JScript, so I wonder, whether it's me being stupid and ignorant about some specific details, or not?

+1  A: 
button(0).click;

Is a reference to a function.

button(0).click();

Would be the function call.

(Also, shouldn't it be square brackets?)

bobince
ashamed. :) thaks. (no, it works fine with these)
be here now