多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

Selenium启动firefox、ie、chrome各浏览器方法

更新时间:2022-04-25 09:15:15 作者:多测师 浏览:209

  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);

Selenium启动firefox、ie、chrome各浏览器方法

  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();

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

  4、启动浏览器的过程中,经常出现启动浏览器窗口,却没有完成输入url地址的情况,大部分由于版本不兼容造成的。

  比如:火狐的会报如下错误

  org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.

  以上内容为大家介绍了自动化测试中的Selenium启动firefox、ie、chrome各浏览器方法,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部