C#调用chrome edge

1.安装selenium支持包和webdriver.

 2.最后一个webdriver不知道是不是老版本的edge里用的。安了也不能正常使用。去https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/下载和自己浏览器大版本号一致的webdriver.,可以只用32位的来适应32/64位。也可以到时候在x64程序中放入替换。chrome edge driver的名字为msedgedriver.exe.改为MicrosoftWebDriver.exe。原来的driver文件夹里一百多kb的MicrosoftWebDriver.exe删了。

using OpenQA.Selenium;
using System;
using System.Threading;

namespace Appse
{
    class Program
    {
        static void Main(string[] args)
        {
            using (IWebDriver driver = new OpenQA.Selenium.Edge.EdgeDriver())
            {
                driver.Navigate().GoToUrl("https://www.baidu.com");  //driver.Url = "https://www.baidu.com"是一样的
                driver.FindElement(By.Id("kw")).SendKeys("如果岁月可以回头");//填文本
                driver.FindElement(By.Id("su")).Click();//点击搜索按钮
                Thread.Sleep(2000);//延时
                var source = driver.PageSource;
                // driver.Close();          关闭浏览器当前打开的最后一个窗口
                driver.Quit();//           关闭WebDriver和所控制的浏览器打开的所有窗口
                Console.WriteLine(source);
                Console.ReadKey();

            }
        }
    }
}

效果如下:

猜你喜欢

转载自blog.csdn.net/qq_24499417/article/details/105535043