本文介绍了网站自动化使用C#和web浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立这将打开WebBrowser控件一个网站,然后把一些文字字段,然后点击几个按钮提交了一个又一个的应用程序。

I am building an application which opens a website in WebBrowser control and then puts some text in fields and then clicks submits on few buttons one after another.

看一看code波纹管...

Have a look at code bellow...


var doc = webBrowser1.Document.GetElementById("ddlOnBoro");
doc.SetAttribute("SelectedIndex", "3");
var temp = doc.InvokeMember("change");

doc = doc.Document.GetElementById("iddOnstreet_txTextBox");
doc.SetAttribute("value", "ASTOR PLACE");

var adoc = doc.Document.GetElementById("Button6");
var getCrossStreets = adoc.DomElement as mshtml.HTMLInputButtonElement;
adoc.RaiseEvent("onclick");

第一次和最后3行的工作很好,即使是中等2工作正常,但当我在code的最后一行的RaiseEvent(onclick事件),文本框的值被提交即使我已经将它之前得到空白在code的5日线。

First and last 3 lines work good and even middle 2 works fine but when I RaiseEvent("onclick") in the last line of code, the value of textbox gets blank before being submitted even I've set it in 5th line of code.

该网站已内置到ASP.NET,我认为这是与搞乱的ViewState。

The website is built into ASP.NET and I think this is ViewState that is messing up with.

任何想法?

推荐答案

是基于关闭的Watir并允许网站的单元测试。它也可以用于输入表格数据,从网站刮数据等,它非常适合使用C#的使用。请不要用于邪恶的目的使用。

http://watin.org/ is based off Watir and allows for unit testing of web sites. It can also be used for entering form data, scraping data from web sites, etc. It's perfect for use with C#. Please don't use this for nefarious purposes.

如果你在IE上的网站,将文本框中清除当您单击按钮?如果您尝试复制你的程序正试图用手做同样的事情不会发生,那么你可能会失去了一些东西。 例如,在前三行,你,但你不会在未来2行做到这一点。只要看一眼所说的改变事件(真的onchange我认为这是)不错,这就是你的code和手工做的唯一区别。

If you're on the web site in IE, will the textbox clear out when you click the button? If you try to replicate what your program is trying to do by hand and the same thing does not happen, then you may be missing something. For example, in the first three lines, you call the "change" event (which I think is really "onchange") but you don't do it for the next 2 lines. Just by looking at it, that's the only difference between your code and doing it by hand.

这篇关于网站自动化使用C#和web浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 02:13