Automatically select field

Asked

Viewed 99 times

1

Guys I got a field:

http://prntscr.com/6ynejl

I set to automatically fill in VB:

Me.WebBrowser1.Document.GetElementsByTagName("select").GetElementsByName("NW_State").Item(0).SetAttribute("value", "AK")

But it’s not going at all, I’ve tried so many ways.

1 answer

0

You can retrieve the children’s items from select and iterate for them by selecting the one who has the text sought:

Dim htmlElm As HtmlElement = Me.WebBrowser1.Document.GetElementsByTagName("select").GetElementsByName("NW_State").Item(0)
    For Each item As HtmlElement In htmlElm.Children
        If (item.InnerHtml = "AZ") Then
            item.SetAttribute("selected", "selected")
        Else
            item.SetAttribute("selected", String.Empty)
        End If
    Next

Browser other questions tagged

You are not signed in. Login or sign up in order to post.