Selenium

参考文件:

https://blog.csdn.net/zyp626/article/details/84672454

https://www.cnblogs.com/vaevvaev/p/7041858.html 

http://www.selenium.org.cn/

https://blog.csdn.net/s740556472/article/details/79322047

手册:

https://www.toolsqa.com/selenium-c-sharp/

下载

https://www.toolsqa.com/selenium-webdriver/c-sharp/download-file-using-selenium-and-verifying/

结合autoit 右键下载链接 

https://www.cnblogs.com/tobecrazy/p/3969390.html

chrome插件 Selenium IDE,可以自动记录脚本

https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd

https://www.seleniumhq.org/selenium-ide/

 

1. 下载安装包

先参考nuget来源:https://www.nuget.org/packages/Selenium.WebDriver

在VS2013 nuget控制台中运行:

Install-Package Selenium.WebDriver -Version 3.141.0

  

2. 下载chrome的驱动。

http://chromedriver.storage.googleapis.com/index.html 找到最新版本 2.46

地址:http://chromedriver.storage.googleapis.com/2.46/chromedriver_win32.zip

下载后把这个exe放到chrome的文件夹下面

3. 上代码:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace seleniumTest
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver(@"C:Program Files (x86)GoogleChromeApplication");           
            driver.Navigate().GoToUrl("http://www.baidu.com");
            driver.FindElement(By.Name("tj_trmap")).Click();
            driver.FindElement(By.XPath("//input[@id='sole-input']")).SendKeys("上海");
            driver.FindElement(By.Id("search-button")).Click(); 
            string html = driver.PageSource;
        }
    }
}
原文地址:https://www.cnblogs.com/lhuser/p/10648762.html