VB web浏览器点击按钮 [英] VB WebBrowser click button

查看:628
本文介绍了VB web浏览器点击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此网页: https://www.youtube.com/upload_defaults 结果
我想调用一个函数,然后点击右上角的保存按钮。

On this web page: https://www.youtube.com/upload_defaults
I would like to call a function and then click the "Save" button in the upper right corner.

有没有标识或名称。我怎样才能做到这一点?

There is no ID or Name. How can I do this?

推荐答案

您可以使用不同的CSS类的按钮:帐户保存按钮

You can use the distinct CSS class of the button: account-save-button

在VB.NET中,使用<一个href=\"https://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.getelementsbytagname(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#$c$c-snippet-1\"相对=nofollow> HtmlDocument.GetElementsByTagName 是这样的:

In VB.NET, use HtmlDocument.GetElementsByTagName like this:

Private Sub ClickSaveButton()
    If (WebBrowser1.Document IsNot Nothing) Then 
        Dim Elems As HtmlElementCollection 
        Dim WebOC as WebBrowser = WebBrowser1

    Elems = WebOC.Document.GetElementsByTagName("BUTTON")

        For Each elem As HtmlElement In Elems
            Dim CssClass As String = elem.GetAttribute("classname")

            If ((CssClass IsNot Nothing) And (CssClass.Length <> 0)) Then 
                If CssClass.ToLower().Contains("account-save-button") Then 
                    elem.InvokeMember("click");
                    Exit For
                End If 
            End If 
        Next 
    End If 
End Sub

要只用Web浏览器验证它,从浏览器的开发者控制台,试试这个;它的工作原理,因为YouTube使用jQuery:

To verify it with just a web browser, try this from your browser's developer console; it works because youtube uses jQuery:

$(帐号保存按钮。)点击();

或者纯javascript: document.getElementsByClassName('帐户保存按钮')[0]。点击();

Or pure javascript: document.getElementsByClassName('account-save-button')[0].click();

有关参考,这里是按钮的标记:

For reference, here is the button's markup:

&LT;按钮类=YT-UIX按钮YT-UIX按钮大小默认YT-UIX键式主帐户保存按钮帐户动作按钮TYPE =提交的onclick =返回true;&GT;&LT;跨度类=YT-UIX键含量&GT;保存&LT; / SPAN&GT;&LT; /按钮&GT;

其他的想法:


  • 这基本上是屏幕刮,这可能会导致脆的应用程序时的页面变化,等等。

  • 谷歌可能已经为你正在试图完成一个Web服务API ..但是这是一个很好的问题:
    究竟什么是你想实现什么?什么是上下文?:我们也许能够提出更好的替代解决方案。

  • This is basically screen scraping, which can lead to brittle applications when the page changes, etc.
  • Google may already have a web service API for what you are trying to accomplish.. but that's a good question: What exactly are you trying to accomplish? What is the context? We may be able to suggest a better alternate solution.

更新

我查了的Youtube参考,但我没有看到任何东西设置preferences上传的默认值。

I checked the Youtube API Reference, but I don't see anything for setting preferences for upload defaults.

这篇关于VB web浏览器点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆