Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2139494
  • 博文数量: 103
  • 博客积分: 206
  • 博客等级: 入伍新兵
  • 技术积分: 1819
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-12 10:24
个人简介

效字当先,以质为本。

文章分类
文章存档

2019年(2)

2018年(4)

2017年(7)

2016年(3)

2015年(14)

2014年(33)

2013年(31)

2012年(9)

分类: Java

2015-07-12 13:24:15


点击(此处)折叠或打开

  1. package week2;

  2. import java.io.File;
  3. import java.io.IOException;

  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.chrome.ChromeDriver;
  6. import org.openqa.selenium.chrome.ChromeOptions;
  7. import org.openqa.selenium.firefox.FirefoxDriver;
  8. import org.openqa.selenium.firefox.FirefoxProfile;
  9. import org.openqa.selenium.ie.InternetExplorerDriver;

  10. public class Mybrowsers {

  11.     public static void main(String[] args) {
  12.         // TODO Auto-generated method stub
  13.         myFirefox();
  14.         mychrome();
  15.         myie();

  16.     }
  17.     //启动并加载firebug插件
  18.     public static void myFirefox(){
  19.         //加载firebug插件
  20.         File file = new File("files/firebug-1.8.4.xpi");
  21.         FirefoxProfile firefoxprofile = new FirefoxProfile();
  22.         try{
  23.             firefoxprofile.addExtension(file);    
  24.         }catch(IOException e){
  25.             e.printStackTrace();
  26.         }
  27.         //设置firebug插件属性
  28.         firefoxprofile.setPreference("extension.firebug.currentVersion", "1.8.4");
  29.         //启动firefox
  30.         WebDriver webdriver = new FirefoxDriver(firefoxprofile);
  31.         webdriver.get(" style="color:#0000CC;">);
  32.         //注意这里 Driver.Quit()退出driver;Driver.Close()关闭当前窗口;
  33.         webdriver.close();
  34.     }
  35.     public static void mychrome(){
  36.         //设置chrome打开路径
  37.         System.setProperty("webdriver.chrome.driver", "files/chromedriver.exe");
  38.         //加载插件
  39.         ChromeOptions options = new ChromeOptions();
  40.         File file = new File("files/Video-Sorter-for-YouTube_v1.1.2.crx");
  41.         options.addExtensions(file);
  42.         //启动chrome浏览器
  43.         WebDriver driver = new ChromeDriver();
  44.         driver.get(" style="color:#0000CC;">);
  45.         driver.quit();        
  46.     }
  47.     public static void myie(){
  48.         //ie无插件可加载
  49.         System.setProperty("webdriver.ie.driver", "files/IEDriver.exe");
  50.         WebDriver driver = new InternetExplorerDriver();
  51.         driver.get(" style="color:#0000CC;">);
  52.         driver.close();    
  53.     }

  54. }

阅读(3506) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

aishiyue2015-07-15 13:25:54