標籤:file ram 建立工程 方便 drive exception 低版本 exce ring
一、環境配置
1、下載selenium-java-2.53.0,並解壓,下載selenium-server-standalone-2.53.1.jar(官網下載)
2、下載eclipse(Version: Neon.1a Release (4.6.1)) 官網下載的最新版
3、安裝jdk(1.8版本) ,我之前裝的是1.7,不支援eclipse最新版,只好卸載重裝了1.8
4、firefox 45(要使用較低版本的firefox,否則與selenium2不相容,導致無法掉起)
二、建立工程
1、開啟eclipse->建立工程tests
2、匯入selenium-java-2.53.0.jar、selenium-server-standalone-2.53.1.jar(步驟:工程名右鍵->Build path->Add Libraries)
3、建立類Seleniumcn,代碼如下
package tests;import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class Seleniumcn {publicstatic void main(String[] args) { System.setProperty ("webdriver.firefox.bin","C:/Program Files (x86)/Mozilla Firefox/firefox.exe" ); WebDriver driver = new FirefoxDriver(); driver.get("http://www.baidu.com"); WebElement element = driver.findElement(By.name("wd")); element.sendKeys("hello Selenium!"); element.submit(); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println( "Page title is: "+ driver.getTitle());//把頁面title列印出來,方便知曉是否完成搜尋 driver.quit();}}
三、運行
1、開啟firefox,開啟百度,輸入hello Selenium!
2、運行結果:Page title is: hello Selenium!_百度搜尋
windows7 selenium2+java 搭建