java的selenium环境搭建

1.下载jdk1.8   环境变量我的博客有我就不说                   selenium下载地址:http://npm.taobao.org/mirrors/selenium

2.下载eplise  网盘地址:链接:https://pan.baidu.com/s/1zXtQHY5hb2IBolA0PhmmJg 密码:bol4

3.使用WebDriver在Chrome浏览器上进行测试时,需要从http://chromedriver.storage.googleapis.com/index.html网址中下载与本机chrome浏览器对应的驱动程序,驱动程序名为chromedriver;

4.火狐驱动下载地址:https://github.com/mozilla/geckodriver/releases/

5.IE的驱动IEdriver 下载地址:http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/

火狐驱动:http://ftp.mozilla.org/pub/firefox/releases/

谷歌驱动:http://npm.taobao.org/mirrors/chromedriver/

selenium3.5   

firefox 55.0

Firefox driver geckodriver-v0.19.0-win64.zip

各种火狐浏览器版本下载:http://ftp.mozilla.org/pub/firefox/releases/

方法一 添加jar包

官方下载地址: http://www.seleniumhq.org/download/

我的网盘地址: https://pan.baidu.com/s/1zXtQHY5hb2IBolA0PhmmJg 密码:bol4

解压后有四个文件:

2. 添加build path,  项目目录右键 Build Path -> Config build path -> java build Path -> Libraries -> Add JAR 

3. 把libs 文件夹下的jar包,全部添加上,再添加 selenium-java-2.44.0-src.jar和selenium-java-2.44.0.jar

方法二 直接引用selenium-server-standalone.jar

selenium-server-standalone.jar 下载地址也在: http://pan.baidu.com/s/1c1tD6Kw

将selenium-server-standalone.jar 直接添加到java项目中就可以了

 //如果要引入其他包

import org.openqa.selenium.*;

import org.openqa.selenium.chrome.*;

火狐浏览器:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class demo {

public static void main(String[] args) {
// TODO Auto-generated method stub

System.setProperty("webdriver.firefox.bin","E:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.baidu.com/");

driver.quit();
}

}

谷歌浏览器:

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class demo {

public static void main(String[] args) {
// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","你的谷歌驱动地址,切记路径用//");
WebDriver driver = new ChromeDriver();
driver.get("https://www.baidu.com/");

driver.quit();
}

}

IE浏览器

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class demo {

public static void main(String[] args) {
// TODO Auto-generated method stub

System.setProperty("webdriver.ie.driver","你的IE驱动地址,切记路径用//");
WebDriver driver = new lnternetExplorerDriver();
driver.get("https://www.baidu.com/");

driver.quit();
}

}

谷歌浏览器地址:https://www.chromedownloads.net/chrome64win-beta/

下载地址:http://selenium-release.storage.googleapis.com/index.html

火狐驱动日志地址:https://github.com/mozilla/geckodriver/blob/release/CHANGES.md

chromedriver版本支持的Chrome版本
v2.38 v65-67
v2.37 v64-66
v2.36 v63-65
v2.35 v62-64
v2.34 v61-63
v2.33 v60-62
v2.32 v59-61
v2.31 v58-60
v2.30 v58-60
v2.29 v56-58
v2.28 v55-57
v2.27 v54-56
v2.26 v53-55
v2.25 v53-55
v2.24 v52-54
v2.23 v51-53
v2.22 v49-52
v2.21 v46-50
v2.20 v43-48
v2.19 v43-47
v2.18 v43-46
v2.17 v42-43
v2.13 v42-45
v2.15 v40-43
v2.14 v39-42
v2.13 v38-41
v2.12 v36-40
v2.11 v36-40
v2.10 v33-36
v2.9 v31-34
v2.8 v30-33
v2.7 v30-33
v2.6 v29-32
v2.5 v29-32
v2.4 v29-32

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 public static void StartFireFoxLoadPlugin(){
       System.out.println("start firefox browser...");
          System.setProperty("webdriver.firefox.bin", 
                 "D:/Program Files/Mozilla Firefox/firefox.exe");
         File file = new File("files/firebug-1.9.0-fx.xpi");
        FirefoxProfile profile = new FirefoxProfile();
         try {
              profile.addExtension(file);
          } catch (IOException e) {
             e.printStackTrace();
        }
         //设置firebug版本
         profile.setPreference("extensions.firebug.currentVersion", "1.9.0");
         //自动打开firebug
         profile.setPreference("extensions.firebug.allPagesActivation", "on");
         //设置启用firebug网络面板
         profile.setPreference("extensions.firebug.net.enableSites", true);
         //设置启用firebugcookies面板
        profile.setPreference("extensions.firebug.cookies.enableSites", true);
         
         WebDriver driver = new FirefoxDriver(profile);
         driver.get("http://www.baidu.com");
         System.out.println("start firefox browser succeed...");    
     }
posted @ 2018-05-27 20:27  taotao12  阅读(330)  评论(0编辑  收藏  举报