Ashley Ivy
Ashley Ivy

Reputation: 193

Get value of input in vb.net webbrowser?

I have the following input, I want to get it value using vb.net WebBrowser, and then put it into a variable how can i perform that?

<input type="hidden" name="loginurl" value="https://example.com?ctoken=KWYZlCrYxt">

I'm trying to use this code, but i don't know how to put the value i got into a variable:

For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
                'Depending on how the source code is formatted on the tag, you may also try Element.OuterHTML, Element.InnerText and Element.OuterText in the line below
                If Element.OuterHtml.Contains("name=""loginurl""") Then
                    Element.GetAttribute("value")

                    Dim login = value
                     WebBrowser1.Navigate(login)

                    Exit For
                End If

Upvotes: 2

Views: 4656

Answers (3)

easyuser
easyuser

Reputation: 1

Try:

Dim AllElementes As HtmlElementCollection = WebBrowser1.Document.All
    For Each webpageelement As HtmlElement In AllElementes
        If webpageelement.GetAttribute("name") = "loginurl" Then
            Dim login = webpageelement.GetAttribute("value")
            WebBrowser1.Navigate(login)
        End If
    Next

should work.

Upvotes: 0

Evil Toad
Evil Toad

Reputation: 3242

I'd say just assign a variable with Dim attributeValue = Element.GetAttribute("value")... am I missing something obvious here?

For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
    'Depending on how the source code is formatted on the tag, you may also try Element.OuterHTML, Element.InnerText and Element.OuterText in the line below
    If Element.OuterHtml.Contains("name=""loginurl""") Then
        Dim attributeValue = Element.GetAttribute("value")

        Dim login = value
         WebBrowser1.Navigate(login)

        Exit For
    End If

Upvotes: 0

Manju
Manju

Reputation: 728

Drag and drop webbrowser control and use the following snippet

    WebBrowser1.Navigate("https://example.com?ctoken=KWYZlCrYxt")

Here is a good reference

Hope this is useful

Upvotes: 1

Related Questions