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

SendKeys, SendMessage, Send me...

Status
Not open for further replies.

JAG14

Programmer
Sep 26, 2003
469
GB
Hi Guys,

As always I've tried and died on this one so many times...

( START ESSAY :) )

I'm trying to send keys to a WebBrowser control within my program that is connected to an external website.
I can get the start of the procedure to work (shakily, but working.) However it seems to not want to carry on after I reach a certain point.
Basically, the page in question is a Submission page for hotel guest info, and I want to automatically send the file required. Here's the annotated code:

Code:
Private Sub Command1_Click()
    Dim x As Integer
    
    'Open Logon page of Website
    WebBrowser1.Navigate sHotelLogOnPage
    'Wait for Browser
    Do While WebBrowser1.Busy = True
        DoEvents
    Loop
  
    WebBrowser1.SetFocus
    'Wait for Browser
    Do While WebBrowser1.Busy = True
        DoEvents
    Loop
    'Send ENTER Key to Enter Site
    SendKeys "{ENTER}", True
    WebBrowser1.SetFocus
    
    'Wait for Browser
    Do While WebBrowser1.Busy = True
        DoEvents
    Loop
    WebBrowser1.SetFocus
    
    'Send TAB to Activate Page, 
    'SHIFT+TAB to back up to Logon Box
    'USERNAME of User
    'TAB to Password Box
    'PASSWORD of User

    SendKeys "{TAB}"
    SendKeys "+{TAB}"
    SendKeys sHotelUserName
    SendKeys "{TAB}"
    SendKeys sHotelPassword
    
    'Send Three Tabs to Reach SUBMIT Button
    For x = 1 To 3
        SendKeys "{TAB}", True
    Next x
    'SPACE Key to Activate Submit Button
    SendKeys " ", True

    'Wait for Browser
    Do While WebBrowser1.Busy = True
        DoEvents
    Loop
    
    'OPEN Send Page for File Entry
    WebBrowser1.Navigate sHotelSendPage

    'Wait for Browser
    Do While WebBrowser1.Busy = True
        DoEvents
    Loop
    WebBrowser1.SetFocus

    'Wait for Browser
    Do While WebBrowser1.Busy = True
        DoEvents
    Loop

    'Send SEVEN Tabs to Reach Filename textbox
    For x = 1 To 7
        SendKeys "{TAB}", True
    Next x

    'Send Filename
    SendKeys sGuestFileName

    'Send THREE Tabs to Reach SUBMIT Button
    For x = 1 To 3
        SendKeys "{TAB}", True
    Next x
    
    'Send SPACE to activate submit button.
    SendKeys " "
    
       
End Sub

OK, now it fails AFTER it opens the Second Page, i.e.
'OPEN Send Page for File Entry
WebBrowser1.Navigate sHotelSendPage

It actually reaches that page, but will then not send any of the following keystrokes (TAB's etc.)

This is doing my nut in, so to speak, and I need to resolve it. Is there a BETTER method of doing this?
I've looked into the Sendmessage API, but this only week for physical controls? (i.e. not ones contained within the browser control)
Or if there is no better method, Is there a way to fix the problem?

Many thanks in advance, and sorry for the essay!!!

Jag

yosherrs.gif

[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
Jag

I'm sure it's not the solution but your Do Loop is duplicated after "WebBrowser1.Navigate sHotelSendPage"

'Wait for Browser
Do While WebBrowser1.Busy = True
DoEvents
Loop
WebBrowser1.SetFocus

'Wait for Browser
Do While WebBrowser1.Busy = True
DoEvents
Loop

I have only used Sendkeys in Telnet commands and I have to apply a delay between each Sendkeys otherwise the commands don't all get performed.

Could this be the problem with your 7 tab loop?

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top