C#Webbrowser控件检查已加载页面上的复选框 [英] C# Webbrowser control check a checkbox on a page that is loaded

查看:51
本文介绍了C#Webbrowser控件检查已加载页面上的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试检查已通过webbrowser控件加载的网页上的复选框。



这是来自网页的代码



Hello,

I am trying to check a checkbox on a webpage that has been loaded through the webbrowser control.

This is the code from the webpage

<div class="uploadFormLine" id="uploadTerms">
        <input type="checkbox" name="terms" id="terms" onclick="checkTerms()" />
        <label for="terms"><strong></strong></label>
      </div>







我试过



HtmlElement checkBox = doc.GetElementById(terms);

checkBox.InvokeMember(Click);



和...



webBrowser1.Document.GetElementById(terms)。InvokeMember(CLICK);





他们都没有工作..非常感谢...谢谢!




I have tried

HtmlElement checkBox = doc.GetElementById("terms");
checkBox.InvokeMember("Click");

and...

webBrowser1.Document.GetElementById("terms").InvokeMember("CLICK");


neither of them are working..any help would be appreciated...thank you!

推荐答案

你需要 WebBrowser .DocumentCompleted Event [ ^ ]

示例代码:

you need WebBrowser.DocumentCompleted Event[^]
sample code:
webBrowser1.DocumentCompleted +=
        new WebBrowserDocumentCompletedEventHandler(DoSomething);
private void DoSomething(object sender,
    WebBrowserDocumentCompletedEventArgs e)
{
    // find checkbox and invoke here...
}


嘿,



谢谢回复。对不起,我忘了提到我确实有这个代码。我在同一块中的代码使用页面上的文本框但由于某种原因它不会响应复选框。我认为这可能与代码onclick中的html或与另一个名为terms的id混淆有关。我也尝试过聚焦有效但不会点击的文本框。我不确定......它也可能与父元素或子元素有关。如果有人在任何帮助或方向之前解决了这个问题,我希望我的问题很清楚。谢谢。
Hey,

Thank you for the reply. Sorry, I forgot to mention I do have that code. I have code in the same block working with a text box on the page but for some reason it won't respond to the check box. I think it may have something to do with the html in the code "onclick" or a confusion with another id named "terms". I also tried focusing the text box which worked but would not click. I'm not sure really...it might also have to do with parent or child elements. If there is anyone that has solved this before any help or direction would be appreciated and hopefully my problem is clear. Thank you.


这篇关于C#Webbrowser控件检查已加载页面上的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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