Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Executing javascript from a VB.net WebBrowser

Options
  • 15-11-2010 7:00pm
    #1
    Registered Users Posts: 6,465 ✭✭✭


    Trying to access a site through a WebBrowser control in VB.Net, and then click a button or link (I've tried both) that executes javascript.

    I've identified the element I'm trying to sue, and have tried, e.g.:
    elementlist.GetElementsByTagName("a")(j).InvokeMember("click")

    to invoke the click event, but it doesn't seem to do anything.

    I tried executing the script directly with:
    br.Document.Window.DomWindow.execscript("<script goes here>", "JavaScript")

    I'm doing a
    While Not br.ReadyState = WebBrowserReadyState.Complete
        Application.DoEvents()
    End While
    
    afterwards, but it never does anything, just sits there on the same page (the javascript is supposed to navigate to a new page). What am I missing?


Comments

  • Closed Accounts Posts: 48 BingoMingo


    This works for me eg.

    You need to use the FORMS element which has additional functionality and which is normally the container for a command button.

    WebBrowser1.Document.Forms(0).GetElementsByTagName("INPUT").Item(5).InvokeMember("click")

    This takes the first form element (Forms(0)) and clicks the sixth element in the input tag (.item(5))
    Change these depending on your target web page.

    Sometimes there is no tagname so you gotta do it another way. You can Use GetElementByID as shown in the example at the end.


    It also depends on how the HTML is constructed. Also your version of vb.net. I use 2008.
    Can you post the url to the web page or PM it. I will write a snippet.


    Here is a link to a query on CodeGuru which I (TurboBob) attempted to resolve - this might help.

    http://www.codeguru.com/forum/showthread.php?t=499692


Advertisement