星空网 > 软件开发 > ASP.net

Selenium调用Chrome,Firefox,IE

C#环境下,使用Selenium调用不同的浏览器,可以使用如下方法:

 1 IWebDriver driver = null; 2 string Browser =null; 3 if (Browser.Equals("IE")) 4 { 5   InternetExplorerOptions options = new InternetExplorerOptions(); 6   options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; 7   driver = new InternetExplorerDriver(options); 8  9 }10 else if (Browser.Equals("Chrome".ToUpper()))11 {12   driver = new ChromeDriver();13 }14 else15 {16   driver = new FirefoxDriver();17 }

注意实现:

1、使用IE浏览器的时候要在该项目的bin\Debug或bin\Release目录下添加IEDriverServer.exe文件。

    用nuget获取IEDriverServer.exe:Install-Package WebDriver.IEDriverServer.win32

2、使用IE时要取消浏览器的保护模式,添加如下代码。

InternetExplorerOptions options = new InternetExplorerOptions();options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

3、使用Chrome浏览器的时候要在该项目的bin\Debug或bin\Release目录下添加chromedriver.exe文件。

  用nuget获取chromedriver.exe:Install-Package Selenium.WebDriver.ChromeDriver

 




原标题:Selenium调用Chrome,Firefox,IE

关键词:chrome

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流