VB.NET Web浏览器单击按钮

发布于 2024-10-18 02:38:59 字数 208 浏览 6 评论 0原文

我正在一个小型 VB.NET 项目工作,该项目自动填充雅虎注册页面上的字段。有没有办法点击“检查”按钮来查看输入的ID是否正确?

例如,如果输入的 ID 正确,则继续填写该字段,如果不正确,请尝试另一个 ID,然后再次按“检查”按钮。

I am working at a small VB.NET project which autofill the fields on the Yahoo register page. Is there a way to click on "Check" button and see if the entered ID is OK or not?

Something like if the entered ID is OK then proceed further with filling the field, if not, try another ID and press "Check" button again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在你怀里撒娇 2024-10-25 02:38:59

Webbrowser 控件允许您访问网页中的元素,并且可以调用它们的方法,因此像这样简单的操作将单击按钮:

webBrowser1.Document.All("yidHelperBtn").InvokeMember("click");

The webbrowser control lets you access elements within the webpage and you can invoke methods on them, so something as simple as this will click the button:

webBrowser1.Document.All("yidHelperBtn").InvokeMember("click");
薄荷梦 2024-10-25 02:38:59

向您的应用程序添加一个定时器,间隔为 1000 毫秒。下面是代码:

Dim CheckButton, yahooId As HtmlElement
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _ 

Handles WebBrowser1.DocumentCompleted

    yahooId = WebBrowser1.Document.GetElementById("yahooid")
    CheckButton = WebBrowser1.Document.GetElementById("yidHelperBtn")

    yahooId.InnerText = "testID" 'Replace testID by the ID you want

    Timer1.Start() 'Starts the timer: within 1000 ms (1 s). It will execute the Timer1_Tick sub.

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    CheckButton.Focus() 'Give the check button the focus
    SendKeys.Send("{ENTER}") 'Causes the validation of the check button
    Timer1.Stop() 'Stops the timer 
End Sub

我添加了一个计时器,因为浏览器在 WebBrowser1_DocumentCompleted 方法中似乎没有验证 Enter 键。

通过这段代码,你可以知道你输入的id是否正确。它并不完整,但它是一个好的开始,尝试理解它并根据您的需求进行调整。

Add a timer to your application, with an interval of 1000 ms. Here is the code:

Dim CheckButton, yahooId As HtmlElement
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _ 

Handles WebBrowser1.DocumentCompleted

    yahooId = WebBrowser1.Document.GetElementById("yahooid")
    CheckButton = WebBrowser1.Document.GetElementById("yidHelperBtn")

    yahooId.InnerText = "testID" 'Replace testID by the ID you want

    Timer1.Start() 'Starts the timer: within 1000 ms (1 s). It will execute the Timer1_Tick sub.

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    CheckButton.Focus() 'Give the check button the focus
    SendKeys.Send("{ENTER}") 'Causes the validation of the check button
    Timer1.Stop() 'Stops the timer 
End Sub

I added a timer because the browser doesn't seem to validate the Enter key while in the WebBrowser1_DocumentCompleted method.

With this code, you can know if the id you entered is OK or not. It is not complete, but it's a good beginning, try to understand and adapt it for your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文