本文介绍了InvokeMember(QUOT;按一下[)在WebBrowser控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
网站显示表的基于选项可供选择。 HTML是
< TD WIDTH =33%级=续><输入类型=无线电 NAME =gatewayIDV的onclick =setBank(11,0,1)>
< TD WIDTH =33%级=续><输入类型=电台NAME =gatewayIDV的onclick =setBank(3,0,1)>
我要调用字符串setBank(11,0,1)的电台点击。我该怎么办?所有电台名称相同,但的onclick()的参数是不同的。
在JavaScript中有人这样做了一些代码,在这里,但我怎么做这在C#
我尝试这一点,但从来没有工作:
如果(webBrowser1.DocumentText.IndexOf(setBank(11,0,1),StringComparison.InvariantCultureIgnoreCase) > 1)
{
webBrowser1.Document.GetElementById(gatewayIDV)InvokeMember(点击)。
}
JavaScript的:
<$ ,p $ p>
$(td.cont),每个(函数(指数){
$ VAR这= $(本);
VAR gonext = TRUE;
如果($ this.html()搜索(searchStr)= -1。!){
$(文件).BookingEngine(setAutomationRunningStatus,
tabData.automationRunning!);
的console.log(索引+:+ $ this.html()+:);
$ this.children(输入[名称='gatewayIDV'])点击();
。 gonext = FALSE;
}
返回gonext;
});
解决方案
您有多个单选按钮,输入您必须循环通过他们,试试这个:
私人无效Form1_Load_1(对象发件人,EventArgs五)
{
WebBrowser1.Navigate时(URL);
}
私人无效webBrowser1_DocumentCompleted_1(对象发件人,WebBrowserDocumentCompletedEventArgs E)
{
的foreach(EL的HtmlElement在webBrowser1.Document.GetElementsByTagName(输入 ))
{
如果(el.Name ==gatewayIDV)
{
el.InvokeMember(点击);
}
}
}
编辑
有关具体的单选按钮
私人无效Form1_Load_1(对象发件人,EventArgs五)
{
WebBrowser1.Navigate时(@E:\Documents和Settings\Ali\Desktop\ww.html);
}
私人无效webBrowser1_DocumentCompleted_1(对象发件人,WebBrowserDocumentCompletedEventArgs E)
{
的foreach(EL的HtmlElement在webBrowser1.Document.GetElementsByTagName(输入 ))
{
如果(el.Name ==gatewayIDV&放大器;&安培; el.OuterHtml.Contains(setBank(11,0,1)))
{
el.InvokeMember(点击);
}
}
}
a website show a table based options to choose. Html is
<td width="33%" class="cont"><input type="radio" name="gatewayIDV" onclick="setBank(11,0,1)">
<td width="33%" class="cont"><input type="radio" name="gatewayIDV" onclick="setBank(3,0,1)">
i want to Invoke click of radio of string "setBank(11,0,1)". How i do? all radio name are same but onclick() parameter is different.
in JavaScript someone do this some code are here but how i do this in c#
i try this but never work:
if (webBrowser1.DocumentText.IndexOf("setBank(11,0,1)", StringComparison.InvariantCultureIgnoreCase) > 1)
{
webBrowser1.Document.GetElementById("gatewayIDV").InvokeMember("click");
}
JavaScript:
$("td.cont").each(function(index) {
var $this = $(this);
var gonext = true;
if($this.html().search(searchStr) != -1) {
$(document).BookingEngine("setAutomationRunningStatus",
!tabData.automationRunning);
console.log(index+":"+$this.html()+":");
$this.children("input[name='gatewayIDV']").click();
gonext = false;
}
return gonext;
});
解决方案
You have multi radio button input you must loop through them,try this:
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.Navigate("url");
}
private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
{
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("input"))
{
if (el.Name == "gatewayIDV")
{
el.InvokeMember("Click");
}
}
}
Edited
For specific radio button
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.Navigate(@"E:\Documents and Settings\Ali\Desktop\ww.html");
}
private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
{
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("input"))
{
if (el.Name == "gatewayIDV" && el.OuterHtml.Contains("setBank(11,0,1)"))
{
el.InvokeMember("Click");
}
}
}
这篇关于InvokeMember(QUOT;按一下[)在WebBrowser控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!