开发者

HtmlElement.invoke(“click”) doesn't work

开发者 https://www.devze.com 2023-03-26 12:24 出处:网络
I\'m trying to create an application that can fill html form automatically using WebBrowser control(C#). There is a option list on the web page and I can get corresponding elements in the drop down bo

I'm trying to create an application that can fill html form automatically using WebBrowser control(C#). There is a option list on the web page and I can get corresponding elements in the drop down box. But when I call the invokemember("click") methods, there is no responce.Below in the selection element of HTML

<div>
class="ddlcont" style="display: block; width: 150px; top: 414px; left: 790.75px;">   
<a class="select" v="0" href="javascript:;">Not </a>
<a v="419000" href="javascript:;">insure</a></div>

Here is my codes,I find ScrollIntoView and Focus method is ok

HtmlElementCollection element_div=currentWindow.Frames[0].Document.GetElementsByTagName ("div");

foreach (HtmlElement item in element_div)
{
    if (item.GetAttribute("classname") == "ddlcont" && item.Children.Count !=0)
    {
        item.Children[1].ScrollIntoView(true);
        item.Children[1].Focus();
        item.Children [1].SetAttribute("selected", "true");
        item.Children [开发者_如何学Python1].InvokeMember("Click");                    
    }  
}

I am appreciate that if anyone can help me to solve the problem. Thanks for your help!


You may have pasted wrong, but in your example div doesn't have a class.
Look:

<div>
class="ddlcont" style="display: block; width: 150px; top: 414px; left: 790.75px;">  

should be

<div
class="ddlcont" style="display: block; width: 150px; top: 414px; left: 790.75px;">  

(no > on the first line)


Try something like this instead:

Button1.GetType().GetEvent("OnClick").GetRaiseMethod().Invoke(Button1, EventArgs.Empty);

You may need to tweak the syntax a little bit, but this should put you on the right path.

0

精彩评论

暂无评论...
验证码 换一张
取 消