zoukankan      html  css  js  c++  java
  • selenium启动firefox、ie、chrome各浏览器方法

    1、启动firefox浏览器

    a.如果你的本地firefox是默认路径安装的话,如下方式即可启动浏览器

    WebDriver driver = new FirefoxDriver();

    driver.get("http://www.baidu.com");

    b.如果不是默认路径安装,需要先将firefox.exe配置到系统变量中去,如下:

    System.setProperty("webdriver.firefox.bin", "D:\ruanjian\Firefox\azml\firefox.exe");
    driver = new FirefoxDriver();
    String url = "http://www.baidu.com";
    driver.get(url);

    2、启动ie浏览器,由于ie,chrome浏览器的driverServer是由他们自己管理的,我们需要下载相应的驱动,注意区分 32位和64位,使用方法如下:

    System.setProperty("webdriver.ie.driver", "src\main\resources\IEDriver.exe");

    WebDriver driver = new InternetExplorerDriver();
    driver.get("http://www.baidu.com");
    同样,如果ie不是默认路径安装需要配置bin路径到系统属性中去
    Tip:加载IEDriverServer的时候,通常会因为兼容模式的设置问题,而无法启动,尝试在创建IEDriver对象的时候 加入合适的参数设置:
    DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
    ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    WebDriver driver = new InternetExplorerDriver(ieCapabilities);
    3、启动chrome浏览器,需要下载chromedriver驱动
    System.setProperty("webdriver.chrome.driver","C:\Program Files (x86)\Google\Chrome\Application\chromedriver_x64.exe");
    WebDriver driver = new ChromeDriver();

    4、启动浏览器的过程中,经常出现启动浏览器窗口,却没有完成输入url地址的情况,大部分由于版本不兼容造成的。
    比如:火狐的会报如下错误
    org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.
  • 相关阅读:
    生成器
    IO调度算法
    进程与线程
    磁盘阵列(RAID)实例
    KVM虚拟化技术(七)虚拟机配置文件
    查询快递单号-京东快递接口
    快递单号查询快递鸟API接口-优速快递
    查询快递单号-德邦快递
    快递单号查询快递鸟API接口-EMS
    快递单号查询快递鸟API接口--安能快递
  • 原文地址:https://www.cnblogs.com/dieyaxianju/p/5145672.html
Copyright © 2011-2022 走看看