I may be missing a very basic thing, but i just dont understand why this isnt working.
I am looking to fill out some web forms based on some user input.
I have already written this in vbscript where its working flawlessly. Now i want to import it to VB.
My 2 main issues atm.
Before, i would have a piece of code:
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Next
For deciding what Internet Explore window to use. However, if i use this form in VB, i miss out on pretty much any type of event handling. I cant use IsBusy, i cant use DocumentCompleted or anything.
So instead i have to declare IE as a browser.
Dim IE As New WebBrowser
Which seems fine.. Except.. Now i cant navigate anywhere, no browsers are created, theres nothing happening. So when i run my code:
IE.Navigate("www.awebwithusernameandpasswordform.org")
IE.Visible = True
Helem = IE.Document.GetElementById("username")
Helem.Value = "xxxx"
Helem = IE.Document.GetElementById("password")
Helem.Value = "xxxx"
Helem = IE.Document.Forms("signupForm")
Helem.Submit()
It just fails at the element "Username" because it never gets to navigate to the website.
It like it just ignores the IE.Navigate. I have tryed running a new process with process.start() but that doesnt work either, it still isnt opening a webpage for me or anything.
Secondly, i am having major issues having vb checking when a document is completely loaded. In VBS i used
Do while ie.readystate <> 4 or ie.busy or ie.document.readystate <> "complete"
wscript.sleep 500
Loop
Do until ie.document.readystate = "complete"
wscript.sleep 500
Loop
And that works like a charm.
In VB, ie.document.readystate is not recognised, and i cant seem to get DocumentCompleted event handling to work. I have attempted several thing from this website, but either they just make everything hang, or it just doesnt work for various reasons. I have attempted the 2 solutions from How to wait until WebBrowser is completely loaded in VB.NET? but they both just make the script hang.
Any tips would be greatly appreciated..