2013-06-24 41 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 
    } 
} 

謝謝
有一個愉快的一天: )

相關問題