Solved

Automate w/o SendKeys

Posted on 2011-03-20
2
254 Views
Last Modified: 2012-06-27
So I'm learning that sendKeys is not the best idea when trying to automate a web page.  I'm finding many resources for VB.net, but not so much for VB6.

So, Can someone help me figure out how to open www.google.com in webbrowser1, type "Hello World" in the search box and hit submit?
0
Comment
Question by:hrolsons
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
0
 
LVL 13

Expert Comment

by:Chris Raisin
Comment Utility
Create a New Project (Project1)
Add a Form (Form1)
Add a WebBrowser (WebBrowser1) (You will have to add a reference in Components to "Microsoft InternetControls")

Place the code below to the form by double clicking on the form

Maximize the form to full screen (as far as possible) then stretch the Browser to fill the Form.

Run the Project.

Hope that is what you are after.  :-)
Option Explicit

Private bFirstPage As Boolean

Private Sub Form_Load()
    bFirstPage = True
    WebBrowser1.Navigate2 "www.google.com"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  If bFirstPage Then
    bFirstPage = False
    WebBrowser1.Document.All.Item("q").Value = "Hello World"
    WebBrowser1.Document.All("btnG").Click
  End If
End Sub

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now