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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WebBrowser Control - click submit button 2

Status
Not open for further replies.

Tranman

Programmer
Sep 25, 2001
695
US
Hi All,
Let me preface this by saying I am a web rookie, so please keep responses somewhat simple.

I have an app whose purpose is to retrieve the html from a web page and parse it into an Access DB. To get to the page, I first have to log in.

I have code to fill in the UserId and Pwd on the page, but have no idea how to programatically "click" the submit button. The button is defined like so:

<TD align=middle><INPUT type=image height=25 alt=&quot;log in.&quot; width=61 src=&quot;Your Account Login_files/bd_bn_login.gif&quot; border=0 name=submit></TD>

In my program, the submit button is WB1.Document.All(253).

Also, is there a way to programatically &quot;click&quot; on a hyperlink on a page inside the WB control?

Any help would be greatly appreciated.

Paul
 
John,
YOU DA MAN!!!!

Does the same work for &quot;clicking&quot; hyperlinks?

Paul
 
If they have an ID=, else locate it by &quot;hook or crook&quot;
Code:
Dim objElements     As Object
Dim objElement     As Object
Dim objToClick As Object
Set objToClick = Nothing
Set objElements = WebBrowser.Document.All.tags(&quot;a&quot;)
For Each objElement In objElements
    if LCase(objElement.innerText) Like &quot;*whatIwant*&quot; then
    ''if LCase(objElement.outerHtml) Like &quot;*somehtml*&quot; then
        Set mobjToClick = objElement
        exit for
    End if  
Next
if objToCkick Is Nothing) Then objToClick.Click
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
John,
Thank you so much for your help. My program works just the way it was supposed to.

It turned out that I was able to identify the correct hyperlink by the href property. Maybe not the best property... (I think if they move the file, the program will be hosed), but I don't think the file will move for a long, long time.

My understanding of your sample code is that objElements is a collection object that contains all of the anchor type elements??? And you are just looking through the collection until you either find the &quot;right&quot; anchor, or come to the end of the collection?

One question. In the very last line of your code example above, should it be:

if NOT objToClick.....

Regards,
Paul

 
if NOT objToClick...is correct.

objElements is not a VB collection. It is some kind of HTML.something &quot;collection&quot; (Length instead of Count) but I had nothing but problems across different versions of IE until I used As Object for everthing except As WebBrowser. I use For Each because I forgot whether the &quot;collection&quot; starts with 0 or 1 and For/Each is probably faster. I even use Navigate (which does not show up in Intellisense) instead of Navigate2 because Navigate2 is IE 5.
I go almost pure &quot;late binding&quot;.

If you even THINK of using any property or function beyond basic stuff, get to where it is defined in the MSDN CD or on-line and get to the applies to list at the bottom. Placing the cursor over an &quot;Applies to&quot; object opens a pop-up showing the applicable versions. Don't use it if you do not see your lowest IE version.

Try this.

Now press &quot;Sync Toc&quot; at the top of the TOC frame just under &quot;Library Only&quot; to see where you are. Now get to the bottom of the right frame where the &quot;Applies To&quot; is. Put the cursor over &quot;Document&quot;. You now know that you can't use XMLDocument as a property of Document if IE 4.

Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
John,
You stay up all night doing this, too.

I did notice the &quot;length&quot;. Weird.

I'm with you on late binding and for each... this program has so little going on that the tiny bit of extra overhead does not mean anything.

Luckily, all of our computers are IE 6.0, so I have no concerns about version.

Thanks again,
Paul
 
See this

I use WB.Document.ALL.tags(&quot;tagname&quot;) because it always returns a &quot;Collection&quot;. Some other methods return an element if 1 is found or a collection and it is a paan to mess with. Besides, this a single user desktop application and your user will not notice the difference in &quot;human time&quot; between the above and some of the later added shortcut methods. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
I learned all the DHTML on the fly because I needed to get into Equifax for my job and their interface is &quot;human&quot; oriented requiring about 5 interactions just to sign-on. Let me know if you need to strip the &quot;img&quot;s before they are fetched into the browser. Talk about a speed-up. I'm heading to bed. It is 1:30 AM EDT here in OldVirginny. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
John,
How do you strip the images?

We have an internal web app that returns whether or not an NC program has been written for a part...

I am using:
Code:
Do Until WebBrowser.ReadyState = READYSTATE_COMPLETE
  DoEvents
Loop

After the submit, but it still takes too long to load before the next page is shoved through...

I finally added a timer delay, but this still is sketchy...
Code:
Dim TimerX As Double
TimerX = Timer
Do: DoEvents: Loop Until Abs(Timer - TimerX) > 1

If you think removeing the images would help, please post the code.

And while your at it, have a star ;-)

Thanks,
Josh

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Does anyone know how to locate and click a button that is in a frame through visual basic?
This button doesn't show up when I loop through the tags on the HTML document ("a").


 
search for <input> tags instead of <a> tags...


Have Fun, Be Young... Code BASIC
-Josh



PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top