[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Automate w/o SendKeys

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
hrolsons
Asked:
hrolsons
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now