Reputation: 57
I use this for loading a website in IE:
Dim ie As Object
ie = CreateObject("InternetExplorer.Application")
ie.Navigate("http://xxxxxxx.com/login.html")
ie.Visible = True
And this for filling input boxes right after i load the page:
ie.Document.GetElementById("email").SetAttribute("value", "[email protected]")
The problem comes when i want to click a button with the use of my VB app. I use this code in a button:
Dim ie As Object
ie = CreateObject("InternetExplorer.Application")
ie.goback()
Example is to use the back button from IE but even when i use ie.Document.All("Login").InvokeMember("click")
i get a (Exception from HRESULT: 0x80004005 (E_FAIL)) error.
Do i need to tell my commands what tab/window it needs to use or something else i'm missing? I want to do stuff on websites opened with the standard Internet Explorer, i'm using version 11 at the moment (maybe that is a problem ;-))
edit: this is how i solved clicking the login button but i need to click other links by anchor text :(
ie.Document.GetElementById("pass").Focus()
SendKeys.Send("{ENTER}")
Upvotes: 1
Views: 9020
Reputation: 348
The method that you are using will work for IE8 and below. In order to use it with IE9 through IE11, you need to add the following code. This will invoke the event listeners.
Reference Microsoft HTML Object Library.
Dim Click_it As Object
Click_it = ie.document.createEvent("HTMLEvents")
Click_it.initEvent "click", True, False
ie.document.Element_to_Click.dispatchEvent Click_it
Upvotes: 0