[英]Is there a general way to use WebBrowser to click button
There are several existing questions discussing programmatically click Web page button using c# WebBrowser: 有几个现有的问题,讨论使用c#WebBrowser以编程方式单击“网页”按钮:
HtmlElement elem = webBrowser.Document.GetElementById("someid");
elem.Focus();
elem.InvokeMember("click")
elem.RemoveFocus();
This method seems work for www.cars.com. 这种方法似乎适用于www.cars.com。 The button is
该按钮是
<a class="button primary zc-submit" name="submit" id="newSearch" href="/for-sale/searchresults.action"><span name="searchText">Search New</span></a>
But not working for http://www.kbb.com/used-cars . 但不适用于http://www.kbb.com/used-cars 。 The button is
该按钮是
<a class="btnRedGradient fL gobutton" href="javascript:$('#yrmkmdForm').submit();"><span class='btnLeft'></span><span>GO</span><span class='btnRight'></span></a>
I wonder is there any general way to use c# WebBrowser to click button in a form automatically? 我想知道有什么通用方法可以使用c#WebBrowser自动单击表单中的按钮吗?
I highly suggest you check out http://watin.org/ 我强烈建议您查看http://watin.org/
You can navigate and scrape or unit test a web site with much less code then if you just use what c# gives us. 如果只使用c#给我们的代码,则可以使用更少的代码来浏览和抓取或对网站进行单元测试。 For instance, in c# if you want to click a button you need to write additional code to tell the computer to wait until it fires off the next event.
例如,在c#中,如果要单击按钮,则需要编写其他代码来告诉计算机等待,直到它触发下一个事件为止。
With WatiN this is done for you. 使用WatiN,这已为您完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.