C# 导航到页面并单击按钮

C# 导航到页面并单击按钮,c#,C#,我有以下代码: 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()后,我需要模拟按下该页面上的按

我有以下代码:

 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()
后,我需要模拟按下该页面上的按钮。如何执行此操作?

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

比如说

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

您可以使用Internet Explorer COM连接。正如上面提到的@Hans Passant,.

检查一下,这将帮助您自动化所有主要的HTML元素

示例

下面的示例说明了如何使用WatiN根据其
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
    }
}
谢谢你,

祝您度过愉快的一天:)

您是否必须使用internet explorer(例如,您正在加载一个flash对象或站点具有某种ActiveX控件),或者您可以只使用一个浏览器?谢谢大家。我很高兴你的帮助。我试试看。再次感谢大家:)你们还没有完全被理解。这是我的密码。过程p=新过程();p、 StartInfo.FileName=“iexplore.exe”;p、 StartInfo.CreateNoWindow=true;p、 StartInfo.WindowStyle=ProcessWindowStyle.Maximized;p、 StartInfo.Arguments=“www.yandex.ru”;p、 Start();但我需要点击页面。谢谢大家。我很高兴你的帮助。我试试看。再次感谢大家:)