|
Question : Web Browser Control (AxSHDocVw) & sendkeys.. won't work!
|
|
What I need to do is to log into a website, and download a file.
In order to do that I need to use this AxSHDocVw control and sendkeys to tab and enter the username / password, click the download link and save it.
(downloading would be a secondary question) For now I need to figure out how to do the sendkeys.
One of 2 things is happening.
1) the page doesn't have focus, so the sendkeys doesn't happen 2) the sendkeys happens before the page is loaded.. (i tried a thread.sleep, even after the navigate method, but somehow this prevents it from loading until the sleeper is over.. see below!)
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf doNavigate), url) Thread.Sleep(10000) SendKeys.Send("{TAB}") etc etc etc OR browser.Navigate(url) Thread.Sleep(10000) SendKeys.Send("{TAB}") etc etc etc
I also tried it without the sleeper.
I also tried it using the navigate2complete event.
private sub browser_NavigateComplete2(ByVal sender As Object, ByVal e As browser.DWebBrowserEvents2_NavigateComplete2Event) Handles browser.NavigateComplete2
and put the above code int he method. I'm lost!
nothing seems to work.. I can use: System.Diagnostics.Process.Start(url) but if i use that I have no way of closing the browser (intelligently) after the sendkeys stuff has done its thing on the web browser (this DOES work, because the sleep function doesn't prevent the browser from loading.)
HELP!
|
|
Answer : Web Browser Control (AxSHDocVw) & sendkeys.. won't work!
|
|
I use the MSHTML library, and the DocumentComplete event, and go through the HTML looking for the right control, and use the appropriate methods to accomplish this task:
Dim doc As HTMLDocumentClass = Me.browser.Document
Dim elem As HTMLInputElementClass = doc.getElementById("SimpleSearchText") elem.focus() elem.value = StripChars(title)
Dim button As HTMLInputElementClass = doc.getElementById("BasicGo") button.click()
Bob
|
|
|
|