你好我正在创建一个应用程序要登录Nexon.net,我无法让它工作,因为文本字段似乎没有使用ID GetElementByID
....
这是我试过的代码但它没有工作= /
Dim Username, Password As String
Username = TextBox1.Text
Password = TextBox2.Text
WebBrowser1.Document.GetElementById("userID").SetAttribute("value", Username)
WebBrowser1.Document.GetElementById("password").SetAttribute("value", Password)
WebBrowser1.Document.GetElementById("gnt_login_submit").InvokeMember("click")
我试图用它来验证登录但是不起作用
If (Not WebBrowser1.Document.All.Item("gnt_play_button") Is Nothing) Then
MsgBox("Incorrect Username/password , ", 0, "Login error!")
答案 0 :(得分:0)
改为使用Document.All
:
WebBrowser1.Document.All("userName").SetAttribute("value", Username)
WebBrowser1.Document.All("passwordName").SetAttribute("value", Password)
WebBrowser1.Document.All("gnt_login_submitName").InvokeMember("click")
而不是id
,将元素的name
属性值传递给All
,如上所示。
答案 1 :(得分:0)
您的代码工作正常,但问题。是你在加载页面时发送这些值
填写
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
WebBrowser1.Document.GetElementById("userID").SetAttribute("value", "User")
WebBrowser1.Document.GetElementById("password").SetAttribute("value", "Pass")
WebBrowser1.Document.GetElementById("gnt_login_submit").InvokeMember("click")
End Sub
并检查