码迷,mamicode.com
首页 > 其他好文 > 详细

Selenium->打开和关闭浏览器

时间:2014-11-18 15:54:41      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   ar   os   使用   sp   div   

一.打开浏览器,两种方式

(1)打开默认路径的firefox

WebDriver driver = new FirefoxDriver();

(2)打开指定路径的firefox,方法1

如果FF没有安装在默认路径上,可以使用该方法

System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");
    
WebDriver driver = new FirefoxDriver();
    
driver.navigate().to("http://ucenter.51cto.com/reg_01.php");

(3)打开指定路径的FF,方法2

File pathToFirefoxBinary = new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");
    
FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
    
WebDriver driver1 = new FirefoxDriver(firefoxbin,null);

打开指定路径的IE和Chrome方法和上述一个原理

 

打开浏览器之后,我们就可以打开一个链接了。可以通过两种方式。

(1)

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

(2)

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

 

 


 

 

二、关闭浏览器

测试完成之后,需要关闭浏览器,可以使用

(1)

driver.quit();

(2)

driver.close();

 

Selenium->打开和关闭浏览器

标签:style   blog   http   color   ar   os   使用   sp   div   

原文地址:http://www.cnblogs.com/LoveTest/p/4105948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!