John Kens
John Kens

Reputation: 27

How to press a button in vb.net web-browser

Hello I'm working on a easy account menu for signing into steam via web-browser. I'm trying to make a button auto sign in the person. I'm able to have the button auto fill the password and the username, but the submit button will not work.

Here is the link to steam's login: Here

Here is the element view of the button. Also note that it looks like it branches to maybe some kind of event? enter image description here

I'm kind of stumped on how to approch this. Is there a way I can use web-console to submit it that way? Here is what I got so far:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    WebBrowser1.ScriptErrorsSuppressed = True

    WebBrowser1.Document.GetElementById("input_username").SetAttribute("value", TextBox1.Text)

    WebBrowser1.Document.GetElementById("input_password").SetAttribute("value", TextBox2.Text)

    WebBrowser1.Document.All("login_btn_signin").InvokeMember("click")

End Sub

Upvotes: 0

Views: 2023

Answers (1)

Visual Vincent
Visual Vincent

Reputation: 18310

After examining your image properly I noticed the you are clicking the wrong element. That <div id="login_btn_signin"> element is just a container and doesn't do anything. You should be clicking the underlying <button> element.

Since the button itself doesn't have an ID you'll have to use a workaround:

'Get the "login_btn_signin" parent/container div.
Dim LoginButtonContainer As HtmlElement = WebBrowser1.Document.GetElementById("login_btn_signin")

'Get the first found <button> element in the container div.
Dim LoginButton As HtmlElement = LoginButtonContainer.GetElementsByTagName("button")(0)

'Click the button.
LoginButton.InvokeMember("click")

Upvotes: 1

Related Questions