WebBrowser Click Button (JavaScript) [Resolved]
Hi Guys,
This on is a little tricky.....
I have an ADSL Moden that I want to be able to control (thru code) the Wireless function (Enable/Disable).
Sounds easy enough, except there is NO elements that I can use!
The HTML (containing JavaScript) dosn't alude to any "Button" Names or ID's.
I first need to select the button to open a new controlbox (not window, as this stays the same URL) to get to the CheckBox that performs the Wireless control. I also cannot manipulate
this checkbox even when I manualy navigate to this spot! - I get Object not set with .... dialog.
I therefore asumed that the Webbrowser, for what ever reason, isn't holding those objects.
In any case, first things first - I need to be able to .Click that first button :)
I have exhausted my use/knowledge of DOM etc.
Ideas?
(PS I will upload the HTML latter)
Cheers 'n' Beers,
Bruce.
Re: WebBrowser Click Button (JavaScript)
Re: WebBrowser Click Button (JavaScript)
Also, this thread contains allot of good web page automation and parsing techniques.
Data From Webpage
Ps, sup Brucy Bruce
Re: WebBrowser Click Button (JavaScript)
Thanks David and Rob :wave:.
I'm at home now and trying a few things :)
Bruce.
Re: WebBrowser Click Button (JavaScript)
Ok, those methods were similar to what I was doing.
(Also, for what it's worth, I had searched all day, and never came across that post!!)
Anhoo,
I still cant get passed the Run-Time Error '91' With Block Variable yada yada...
However, I need to go back one step, and .Click one of those 'java' buttons.
Attached is the HTML page (text view) and associated controlpanel.
The button in question is "Wireless".
As you can see there is no Button objects...
(Please note I have two issues. 1. Clicking a button, and 2. in another controlset (display of buttons/checkboxs), clicking a CheckBox)
I will say at this time that the CheckBox issue is ovevercome by generating errors on that page load????? If a browser error occurs, I can .Click the CheckBox after cycling the error prompts.... (caching?)
Bruce.
Re: WebBrowser Click Button (JavaScript)
Well, for starters, just the HTML page doesn't do much without the JavaScript file that contains the code to generate the menu. :) Can you attach that one as well (../html/js/menu.js).
As for the problem at hand, try viewing the HTML of the body at runtime, when the navigational buttons have been created (document.body.innerHTML). That code should include all generated content. You may be able to extract info of the buttons from there. :)
Re: WebBrowser Click Button (JavaScript)
Thanks for the reply Vader :)
Ok, I have attached the JS file (as menu.txt(zip)), and the results of the innerHTML after the page had loaded as innerHTML.txt.
Note: I have many times tried to navigate to the wireless.htm directly thru code, but that generates browser errors. I guess there are a few unset variables that are requried - hence the browser errors. Because of this I have tried to submit a .Click to the 'wirless' button.
VB Code:
WebBrowser1.Document.location.href = "../cgi-bin/webcm?getpage=../html/home/home_wizard.htm"
innerHTML Results:
Quote:
<FRAME name=fPanel marginWidth=0 marginHeight=0 src=""><FRAME name=fInfo src="../cgi-bin/webcm?getpage=../html/home/home_RelaodHref.htm&var:RelaodHref="><NOFRAMES>
<body bgcolor="#008080">
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</NOFRAMES>
(PS I have clipped the tail end of the attached Java Code (menu.txt))
Regards,
Bruce
Re: WebBrowser Click Button (JavaScript)
I don't understand much of the structure of that site... but it looks like the index page is a frameset that contains other pages. You can get to those pages with the document.frames collection.
It would be much easier if I could just navigate to the page on the web; can you post the URL? I get script errors when I try to open mytext.htm with menu.js. :)
Re: WebBrowser Click Button (JavaScript)
Unfortunatly I cannot provide the URL, as its internal to my ADSL Modem.
I will try to iterate Frame collection :)
Bruce.
Re: WebBrowser Click Button (JavaScript)
Okay; this piece of code may help you. It adds all (inline) frames (including nested ones) to a collection colDocuments. You can use items from colDocuments just like any other document object (e.g. you can use colDocuments(0).body.innerHTML). :)
VB Code:
Private Sub GetFrames()
'Purpose: searches all frames in the document(s) and adds them to colDocuments
Dim i As Integer, j As Integer
j = 1
Set colDocuments = New Collection
colDocuments.Add WebBrowser1.Document
Do While j < colDocuments.Count + 1
For i = 0 To colDocuments.Item(j).frames.length - 1
colDocuments.Add colDocuments.Item(j).frames.Item(i).Document
Next i
j = j + 1
Loop
End Sub
Re: WebBrowser Click Button (JavaScript)
Ok, thats what I needed. I now have the TD/TR matrix.
I will try to iterate thru that and on match, perform a .Click (to envoke the "doLink('/html/home/wireless.htm')!
Bruce.
Re: WebBrowser Click Button (JavaScript)
I have beena ble to load the Collection, iterate thru and determine the index/location of the TD containing the 'Wireless' tag.
Now I have that, I cannot work out the syntax to be used on the WebBrowser.Document to perform a .Click on that item?
VB Code:
WebBrowser1.Document.All.Item(3).body.innerHTML.getElementsByName("TD").Item(8).Click
:)
Bruce.
Re: WebBrowser Click Button (JavaScript)
The syntax is fine, but you shouldn't use the WebBrowser1.Document object... just call the Click event from the colDocuments collection. :)
Re: WebBrowser Click Button (JavaScript)
Vadar, you Guru you!
Thankyou for your persistance.
Solution:
VB Code:
colDocuments(3).getElementsByName("TD").Item(10).Click
All the best with you problem too :)
Regards,
Bruce.
Re: WebBrowser Click Button (JavaScript)
You're welcome. :) As for my problem: I've found a satisfying work-around; but it remains strange behavior...