我的应用程序是某种迷你网络浏览器应用程序。在我的应用程序中,我有用于登录 Google 的按钮,它将完成 Google 的“登录” 或更具体的“下一步” 按钮的工作。我可以使用 Inspect Elements 获取 ElementId 并且按钮的 ElementId 是 "passwordNext" 强>。但是,当我尝试使用我的按钮单击按钮时,它失败了,就好像程序找不到任何具有此 Id 的元素。
Screenshot (ElementId for 'Next' Button):
Code:
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
If Not IsNothing(wbMain.Document.GetElementById("passwordNext")) Then
wbMain.Document.GetElementById("passwordNext").InvokeMember("Click")
End If
End Sub
最佳答案
请记住 WebBrowser
控件使用旧的 IE 版本(不一定是您安装的最新版本),我注意到您正在使用 Chrome 进行调试(我一开始也是)。如果您查看网络浏览器生成的源代码,您会注意到该按钮具有不同的 ID id="next"
。所以只需将您的代码更改为如下所示:
If Not IsNothing(wbMain.Document.GetElementById("next")) Then
wbMain.Document.GetElementById("next").InvokeMember("Click")
End If
你应该可以开始了。
关于javascript - 无法在 Webbrowser #Vb.net 上通过其已知的元素 ID 单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46817731/