Criel
Criel

Reputation: 815

How to find an element post button click - Web browser vb.net

I'm experiencing an issue when trying to push a button through a webbrowser control and having an error occur on that button click(incorrect information entered as an example). When i try to find the element of the error through the webbrowser it never finds it due to the page elements being loaded prior to the error occuring so the error elements aren't in the htmlelementcollection. Is there a way to add these dynamically in certain situations where an error occurs so I could search by the error classname and have the webbrowser pick it up?

Here's a small snippet of the code

...
For Each curElement3 As HtmlElement In collP
    Dim controlName3 As String = curElement3.GetAttribute("classname").ToString
    If controlName3 = "submit_error" Then
        MessageBox.Show("An error has occured")
    End If
...

Upvotes: 0

Views: 548

Answers (2)

SysDragon
SysDragon

Reputation: 9888

If WebBrowser1.Refresh() didn't work for you then you need to force the document to reload so you can retrieve the new values.

Try this:

Dim args() As Object = New Object() {"someparameters"}
webBrowser1.Document.InvokeScript("__doPostBack", args)

Upvotes: 1

washcloth
washcloth

Reputation: 2896

Have you tried using a different attribute to get the button? I was experiencing a similar before and it was due to the fact that their was more then one button with the field I was checking. So try looking at a different attribute or use an AND statement to check more than attribute at a time.

Upvotes: 1

Related Questions