zoukankan      html  css  js  c++  java
  • 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 else
    15 {
    16   driver = new FirefoxDriver();
    17 }

    注意实现:

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

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

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

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

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

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

  • 相关阅读:
    C#遍历List并删除某个或者几个元素的方法
    7月清北学堂培训 Day 4
    7月清北学堂培训 Day 3
    7月清北学堂培训 Day 2
    7月清北学堂培训 Day 1
    P1383 高级打字机
    P2401 不等数列
    P1412 经营与开发
    P1314 聪明的质监员
    2019.7.9 校内测试 T3 15数码问题
  • 原文地址:https://www.cnblogs.com/beagreatman/p/5978137.html
Copyright © 2011-2022 走看看