简体   繁体   English

C#WebBrowser HTMLElement.InvokeMember(“click”)无效 <form> 标签

[英]C# WebBrowser HTMLElement.InvokeMember(“click”) not working within <form> tag

I'm writing a C# form application which automates some user behaviour by clicking through buttons, links, forms, etc in a WebBrowser. 我正在编写一个C#表单应用程序,它通过单击WebBrowser中的按钮,链接,表单等来自动执行某些用户行为。 Everything worked fine, im using InvokeMember("click") without problem on several buttons and links, but now i'm stuck with one click. 一切正常,我使用InvokeMember(“点击”)没有问题几个按钮和链接,但现在我只需点击一下就可以了。

I'm struggling for days, and i have tried several tips, but nothing worked yet. 我挣扎了几天,我尝试了几个技巧,但还没有任何效果。 The HTML code with the form basically looks like the following: 表单的HTML代码基本如下所示:

<form name="shipsChosen" id="shipsChosen" method="post" action="http://www.example.com/index.php?page=2">

<li class="off" id="button1">
            <div class="buildingimg"><a  href="javascript:void(0);"></a></div>
            <input id="ship_1"/>
</li>

<li class="off" id="button2">
            <div class="buildingimg"><a  href="javascript:void(0);"></a></div>
            <input id="ship_2"/>
</li>

<li class="off" id="button3">
            <div class="buildingimg"><a  href="javascript:void(0);"></a></div>
            <input id="ship_3"/>
</li>

</form>

<a  href="javascript:void(0);" onClick='setMaxIntInput();' id="sendall"></a>
<a id="continue" class="off" href="" onClick="trySubmit(); return false;"><span>Submit</span></a>

What i want, is to click on the link with "sendall" ID, and then click on the link with "continue" ID. 我想要的是点击带有“sendall”ID的链接,然后点击带有“继续”ID的链接。

I have already tried the followings, but none of them worked. 我已经尝试了以下内容,但它们都没有奏效。 Nothing happens: 什么都没发生:

HtmlElement AllShips = webBrowser1.Document.GetElementById("sendall");
AllShips.RaiseEvent("onclick");
AllShips.InvokeMember("click");

I have also tried to put some value into the input fields, but it's not works neither: 我也尝试在输入字段中加入一些值,但它既不起作用:

HtmlElement Input= webBrowser1.Document.GetElementById("ship_202");
Input.Focus();
Input.InnerText = "ship_1";

It's very interesting to me, since althought it's not working when i run this without any user interaction in my C# form application with WebBrowser, BUT if i click once by myself in the WebBrowser, and run the click codes above, it works. 这对我来说非常有趣,因为当我在使用WebBrowser的C#表单应用程序中没有任何用户交互的情况下运行它时,它不起作用, 但是如果我自己在WebBrowser中单击一次,并运行上面的单击代码,它就可以工作。 But it's not automation right..? 但这不是自动化权利..?

Anyone experienced similar problems like this? 有人经历过类似的问题吗? The only difference i found between the working clicks and in this, is the in the HTML. 我在工作点击之间找到的唯一区别在于HTML。

More: I'm using Internet Explorer 11 FEATURE_BROWSER_EMULATION for the WebBrowser. 更多:我正在为WebBrowser使用Internet Explorer 11 FEATURE_BROWSER_EMULATION。 The page is fully loaded. 页面已满载。

Try letting your application pause before invoking the clicks and between them, because the page may still be busy with some earlier processes. 尝试让您的应用程序暂停,然后再调用它们之间的点击,因为页面可能仍然忙于某些早期的进程。 you can use a timer control for that effect. 您可以使用计时器控件来实现该效果。

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

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