首页 > 其他 > 详细

Selenium2浏览器启动及配置

时间:2015-10-14 11:46:10      阅读:270      评论:0      收藏:0      [点我收藏+]

启动浏览器

  SELENIUM2在启动浏览器时,都是启动一个干净的没有任何插件及cookies信息的浏览器;

 技术分享
1     public static void myfirefox()
2     {
3         System.setProperty("webdriver.firefox.bin","D:/Mozilla Firefox/firefox.exe");
4         WebDriver driver=new FirefoxDriver();
5         Navigation navigation=driver.navigate();
6         navigation.to("http://www.baidu.com");
7     }
View Code

  ——注:如果浏览器安装时为默认路径安装,则可以去掉:System.setProperty的内容;

启动firefox(加相关插件)

技术分享
 1     public static void myfirefoxplug()
 2     {
 3         //加入firefox插件
 4         File file=new File("files/firebug-2.0.6.xpi");
 5         FirefoxProfile firefoxprofile=new FirefoxProfile();
 6         
 7         //捕捉加载firefox的异常
 8         try{
 9             firefoxprofile.addExtension(file);
10         }
11         catch(IOException e)
12         {
13             e.printStackTrace();
14         }
15         //WebDriver driver=new FirefoxDriver(firefoxProfile);
16         //设置firebug的版本号
17         firefoxprofile.setPreference("extensions.firebug.currentVersion", "2.0.6");
18         //非默认路径下修改路径
19         System.setProperty("webdriver.firefox.bin","D:/Mozilla Firefox/firefox.exe");
20         
21         //实例化一个driver对象
22         WebDriver driver=new FirefoxDriver(firefoxprofile);
23         
24         //跳转实例
25         Navigation navigation=driver.navigate();
26         navigation.to("http://www.baidu.com");
27 
28     }
View Code

启动chrome

技术分享
1     public static void mychrome()
2     {
3         System.setProperty("webdriver.chrome.driver", "files/chromedriver.exe");
4         WebDriver driver=new ChromeDriver();
5         Navigation navigation=driver.navigate();
6         navigation.to("http://www.sina.com");
7         
8     }
View Code

启动IE

技术分享
1     public static void myie()
2     {
3         System.setProperty("webdriver.ie.driver", "files/IEDriverServer.exe");
4         WebDriver driver=new InternetExplorerDriver();
5         Navigation navigation=driver.navigate();
6         navigation.to("http://www.sohu.com");
7         
8     }
View Code

插件下载地址如下:http://pan.baidu.com/s/1pJy3Dc3

Selenium2浏览器启动及配置

原文:http://www.cnblogs.com/leoliyue/p/4876731.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!