简体   繁体   English

c#Web浏览器模拟按钮按下

[英]c# Web Browser simulate button press

I'm using the WebBrowser control and want to bypass a button press on a web page. 我正在使用WebBrowser控件,并希望绕过网页上的按钮按下。 I'm not very familiar with HTML and web pages, but I'm wondering if anyone has a solution. 我对HTML和网页不是很熟悉,但是我想知道是否有人有解决方案。

The button I'm talking about is on this web page: http://www.movshare.net/video/ut55cfdvg5wgj/ ? 我正在谈论的按钮在此网页上: http : //www.movshare.net/video/ut55cfdvg5wgj/

The button is appearing at random so it might not be there always. 该按钮随机出现,因此可能并不总是存在。

Do you want the user to skip the button press everytime. 您是否希望用户每次都跳过按钮按下。 Then this means, you don't need the button at all on the page. 这意味着,您根本不需要页面上的按钮。 Please put more information 请输入更多信息

Edit: Thinking about this, you can do most of this from the C#. 编辑:考虑到这一点,您可以从C#中完成大多数操作。 Updated. 更新。

Get a reference to the button and invoke it's click() JavaScript method: 获取对该按钮的引用并调用它的click() JavaScript方法:

HtmlElement btn = myBrowserControl.Document.GetElementById("myButton");
/*
Alternatively, take a look at these other methods for retrieving an HtmlElement:
HtmlDocument.GetElementFromPoint(Point point)
HtmlDocument.GetElementsByTagName(string tagName)
HtmlDocument.All.GetElementsByName(string name)
*/
btn.InvokeMember("click");

This will only work in all browsers if ... 这仅适用于所有浏览器,如果...
Since this is a WebBrowser control, you don't need to worry about cross browser issues. 由于这是一个WebBrowser控件,因此您无需担心跨浏览器问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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