首页 > 其他 > 详细

Selenium调用Chrome,Firefox,IE

时间:2016-10-19 19:59:38      阅读:232      评论:0      收藏:0      [点我收藏+]

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 else
15 {
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

原文:http://www.cnblogs.com/beagreatman/p/5978137.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!