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.
  • 相关阅读:
    flash 中无法导出swf文件的解决方法
    codeforces 341C Iahub and Permutations(组合数dp)
    CSS里的 no-repeat 是什么意思
    linux enable命令学习
    config large memory
    java中集合杂记
    Linux操作系统以及各大发行版介绍——Linux operating system and major distribution is introduced
    KVM几种缓存模式
    Elastic-Job
    日交易额百亿级交易系统的超轻量日志实现
  • 原文地址:https://www.cnblogs.com/dieyaxianju/p/5145672.html
Copyright © 2011-2022 走看看