VB.net how to control IE the right way

1

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", "my@mail.com")

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}")
vb.net
internet-explorer
asked on Stack Overflow Feb 5, 2014 by Maarten

1 Answer

0

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
answered on Stack Overflow May 11, 2016 by Josh Anstead • edited May 12, 2016 by Josh Anstead

User contributions licensed under CC BY-SA 3.0