简体   繁体   中英

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? 在此处输入图片说明

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

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM