Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript - Click an untypical button on website

Status
Not open for further replies.

Bartias

Technical User
Dec 1, 2013
8
0
0
PL

Hello,

I cannot figure out how do I make vbscript click a button on a webpage which, according to "Inspect Element" is represented by this code:

Code:
<td class="a" id="logout" onclick="BtnClickPreHandler(this);" onmouseover="HoverOn(this)" onmouseout="HoverOff(this);" title="Log out">
    <img class="d" id="logout_d" src="/style/2011/images/buttons/logout_up.gif" style="display: none;">
    <img class="a" style="" id="logout_a" src="/style/2011/images/buttons/logout_up.gif">
    <img class="h" style="display: none;" id="logout_h" src="/style/2011/images/buttons/logout_up.gif">
    <span id="logout_s" class="a">Log out</span>
</td>

I was able to click normal buttons with something like
Code:
appIE.Document.getElementsByName("Submit").Item(0).Click
, however in this case I cannot reference the object correctly.

I tried this
Code:
objButton = appIe.Document.GetElementByID("logout") msgbox typename(objButton)
and the result was "Null". When I tried the same for a previous button that I am able to click with
Code:
appIE.Document.getElementsByName("loginSubmit").Item(0).Click
, the result was "String". However, there the code was
Code:
 <button name="loginSubmit" type="submit">

Any ideas how do I click the <td> buttons? Most of the buttons on this website are as cells of a table.
 
Just call the event listener in the onClick attribute.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I'm sorry - how do I do that? You can probably tell that I am a beginner, so I can't even get to catch the reference to this object...
 
This
Code:
onclick="BtnClickPreHandler(this);
Is what a 'click' would do, you simply call that same function and replace 'this' with Document.GetElementByID("logout")

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I tried this in these three ways, but I get a Type mismatch error:
1.
Code:
Function buttonclicker
	call BtnClickPreHandler(appIE.Document.GetElementByID("logout"))
End Function
2.
Code:
appIE.document.parentWindow.BtnClickPreHandler(appIE.Document.GetElementByID("logout"))
3.
Code:
Call BtnClickPreHandler(appIE.Document.GetElementByID("logout"))

Also, just to clarify. The idea here is to have a vbs file that I would simply double click and it would go to a webpage (I have no influence over the site's code), it would login in and THEN click some buttons.

Thanks a lot!
 
Also, just to clarify. The idea here is to have a vbs file that I would simply double click and it would go to a webpage (I have no influence over the site's code), it would login in and THEN click some buttons.
Right, so this is not some IE specific UI that you are creating.


I tried this in these three ways,
You do realise that you cannot create a reference to a DOM object until the DOM has been created by opening the the document with a DOM enabled user agent..

And of course the creator of the document will have probably known that and deliberately did not use a submit type input or a button to prevent people doing what you are trying to do, that is 'faking' clicks on a document URL.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I see... Well, the idea here is to create a script for support users (me) to automate user creation process for an internal company system (getting on the basis of the email addresses list, getting Job Title, address and name info for each employee, putting the data into the form and submit). It does indeed sound like a macro for creating spam bots or stuff, but it's not actually the case here.

Clicking on the buttons is rather necessary, otherwise the process will be a bit clumsy. So, are you saying that there is no way of sending a click on the element like this one?

Code:
<td id="print" class="a" title="Print" onmouseout="HoverOff(this);" onmouseover="HoverOn(this)" onclick="BtnClickPreHandler(this);">

Why exactly is it that every time I tried to GetElementById I get a Null value?

Thanks for your help!
 
Why exactly is it that every time I tried to GetElementById I get a Null value

Because the element does not exist.

DOM scripting does NOT use the document source code to reference elements, it uses the object model of the source code that is created in memory as the document is opened in a browser context. Judging by what you have posted, your script is not loading the document before you are trying to reference the elements.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
OK, thanks a lot. Well, I give up trying to click the buttons. I have a workaround though! I will click the buttons myself, while the script will monitor whether the relevant page has loaded - as soon as it loads, it will fill in the forms, then I will click another button and the script notice that the page has changed, fill in another forms, and then I will submit!

Not as good, but still not bad;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top