標籤:java 朋友 開發 項目 selenium2
一、開發環境:
1、安裝JDK:
http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html
2、安裝Eclipse
http://www.eclipse.org/downloads/
3、安裝Selenium:(Java版本)
http://www.selenium.com/
目前Selenium官網被封殺,有需要的聯絡聯絡我。或者使用代理訪問。
二、建立Java項目與Manve項目
前提條件:
1、JDK配置成功
2、Eclipse能正常使用
3、Selenium(Java版本現在完成)
注意:建立Manve項目需要搭建Manve環境。這裡暫時不說明,有需要的朋友可以聯絡我。QQ:807002272
-
新增Java項目[開啟Eclipse—>File—>New—>Other—>Java Project
650) this.width=650;" src="http://img.blog.csdn.net/20150706140012616" alt="這裡寫圖片描述" title="" style="border:none;height:auto;" />
650) this.width=650;" src="http://img.blog.csdn.net/20150706141045600" alt="這裡寫圖片描述" title="" style="border:none;height:auto;" />
650) this.width=650;" src="http://img.blog.csdn.net/20150706141002318" alt="這裡寫圖片描述" title="" style="border:none;height:auto;" />
-
將Selenium配置到項目
將Selenium解壓後,拷貝到剛剛建立的項目裡面。
650) this.width=650;" src="http://img.blog.csdn.net/20150706140813738" alt="這裡寫圖片描述" title="" style="border:none;height:auto;" />
650) this.width=650;" src="http://img.blog.csdn.net/20150706140930025" alt="這裡寫圖片描述" title="" style="border:none;height:auto;" />
-
將Jar包檔案配置到Build Path
650) this.width=650;" src="http://img.blog.csdn.net/20150706141315172" alt="這裡寫圖片描述" title="" style="border:none;height:auto;" />
650) this.width=650;" src="http://img.blog.csdn.net/20150706141540330" alt="這裡寫圖片描述" title="" style="border:none;height:auto;" />
selenium-java-2.46.0.jar
selenium-java-2.46.0-srcs.jar
按照上面圖操作,找到這2個包,進行添加。點擊OK
650) this.width=650;" src="http://img.blog.csdn.net/20150706141848939" alt="這裡寫圖片描述" title="" style="border:none;height:auto;" />
三、測試環境搭建成功
建立一個Java檔案;輸入以下代碼;使用Java Application運行。
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.*; public class Snippet { public static void main(String[] args) { //如果Firefox瀏覽器沒有預設安裝在C盤,需要制定其路徑 System.setProperty("webdriver.firefox.bin", "D:/Firefox/firefox.exe"); WebDriver driver = new FirefoxDriver(); driver.get("http://wd.txiake.com/"); driver.manage().window().maximize(); WebElement txtbox = driver.findElement(By.name("q")); txtbox.sendKeys("20150410"); WebElement btn = driver.findElement(By.id("global_search_btns")); btn.click(); driver.close(); } }
本文出自 “一座舊城,記憶依舊。” 部落格,請務必保留此出處http://diaosi58.blog.51cto.com/2722311/1672000
[Selenium2]+Eclipse+Java環境搭建