2013-06-24 38 views
0

我有以下代码:导航到页面,然后点击一个按钮

Process p = new Process(); 
p.StartInfo.FileName = "iexplore.exe"; 
p.StartInfo.CreateNoWindow = true; 
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; 
p.StartInfo.Arguments = "www.yandex.ru"; 
p.Start(); 

调用p.Start()后,我需要模拟按下此页面上的按钮。我怎样才能做到这一点?

+0

http://msdn.microsoft.com/en-us/library/aa752084%28v=VS.85%29.aspx –

+0

您是否必须使用Internet Explorer(用于考试您是否正在加载Flash对象或该网站有某种ActiveX控件),或者您可以只使用[支持Cookie的WebClient](http://stackoverflow.com/questions/4740752/how-to-login-with- Web客户端-C-锋利/ 4740851#4740851)? –

+0

谢谢大家。我很高兴你的帮助。我会尝试。再一次,谢谢大家:) –

回答

1

您需要运行c:\ program files \ Microsoft \ Internet Explorer \ iexplore.exe或任何浏览器路径,然后将URL作为参数传递到process.start函数。

例如

Process.Start("IEXPLORE.EXE", "http://www.yandex.ru/"); 
+0

你还没有完全明白。这是我的代码。进程p =新进程(); p.StartInfo.FileName =“iexplore.exe”; p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; p.StartInfo.Arguments =“www.yandex.ru”; p.Start();但我需要点击页面。 –

0

您可以使用Internet Explorer COM连接。 For example。正如上面提到的@Hans Passant,here is the documentation

+0

谢谢大家。我很高兴你的帮助。我会尝试。再一次,谢谢大家:) –

1

检出WatIN这将帮助您自动化所有主要的HTML元素。

下面的例子演示了如何使用华廷根据其id属性上的特定页面上的按钮,点击

[STAThread] 
static void Main(string[] args) 
{ 
    using (var _IExplore = new WatiN.Core.IE("http://www.yandex.ru")) 
    { 
     // _IExplore.Button(WatiN.Core.Find.ByName("nameOfButton")).Click(); //Clicks the button according to its name attribute 
     _IExplore.Button(WatiN.Core.Find.ById("idOfButton")).Click(); //Clicks the button according to its id attribute 
    } 
} 

谢谢
有一个愉快的一天: )

相关问题