1、 安裝 jdk并配置環境變量:
jdk安裝
jdk下載地址:?
http://www.oracle.com/technetwork/java/javase/downloads/index.html
環境變量配置,如:
CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
JAVA_HOME=D:\Program?Files\Java\jdk1.6.0_10
PATH=%JAVA_HOME%\bin
2、 安裝 Firefox,Selenium?IDE,Firebug和xpahter
安裝FireFox
Firefox版本有一定限制,需要和selenium?IDE相匹配。
下載地址:?
http://www.firefox.com.cn/download/
?
安裝Selenium?IDE
Selenium?IDE是基于FIREFOX瀏覽器的一個插件,提供GUI界面來運行Selenium測試。Selenium?IDE提供腳本錄制和回放功能,可以將用戶在瀏覽器中執行的操作記錄下來,生成各種形式的腳本,可以將這些腳本保存供selenium使用。
Selenium?IDE
主要是用在
Selenium?1.0
中,在
Selenium?2.0
中基本不使用。
1)下載Selenim?IDE
下載地址:
http://seleniumhq.org/projects/ide/
2)安裝:直接把下載的Selenium?IDE文件拖到FireFox瀏覽器窗口中,按提示操作即可安裝成功。
?
安裝Firebug
1)打開Firefox瀏覽器
2)點擊菜單“工具(T)”,下拉列表中選擇“附加組件”。
3)“獲取附加組件”
4)在搜索里輸入“firebug”,稍等即可。
5)點擊“添加至Firefox”
6)OK,重啟瀏覽器即可。
?
安裝xpahter
1)打開Firefox瀏覽器
2)點擊菜單“工具(T)”,下拉列表中選擇“附加組件”。
3)“獲取附加組件”
4)在搜索里輸入“xpahter”,稍等即可。
5)點擊“添加至Firefox”
6)OK,重啟瀏覽器即可。
?
安裝 xpath?checker
1)打開Firefox瀏覽器
2)點擊菜單“工具(T)”,下拉列表中選擇“附加組件”。
3)“獲取附加組件”
4)在搜索里輸入“
xpath?checker
”,稍等即可。
5)點擊“添加至Firefox”
6)OK,重啟瀏覽器即可。
?
3、 安裝 eclipse
安裝eclipse
?
4、 安裝 selenium?webdriver
1)下載地址:? http://code.google.com/p/selenium/downloads/list
官方 UserGuide : http://seleniumhq.org/docs/
2)下載:selenium-server-standalone-2.44.0.jar和selenium-java-2.44.0.zip(使用java語言的下載該包)。?
3)解壓下載的selenium-java-2.44.0.zip文件
?
5、selenium2使用:
1 )在 Eclipse 里新建一個project ,然后引用 selenium-java-2.44.0.zip 解壓 后的selenium-java-2.44.0.jar,及libs下的jar包 。
2 ) 新建一個 class “Seleniumcn”把代碼貼進去,如果代碼沒錯誤就可以運行了。例如下面:

package com.hxh.test; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import org.testng.annotations.BeforeMethod; import org.apache.commons.lang3.exception.ExceptionUtils; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.BeforeClass; import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium; public class SeleniumTest{ private WebDriver driver; @BeforeMethod @BeforeClass public void setUp(){ System.setProperty( "webdriver.ie.driver", "C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe" ); driver = new InternetExplorerDriver(); } @Test(invocationCount =3 ) public void testLogic(){ driver.get( "http://www.baidu.com/" ); System.out.println( "打開鏈接——>" ); WebDriverWait wait = new WebDriverWait(driver, 100 ); WebElement element = wait.until( new ExpectedCondition<WebElement> () { @Override public WebElement apply(WebDriver d) { return d.findElement(By.id("kw" )); } }); if (element!= null ){ System.out.println( "成功打開連接~~~~~~~~O(∩_∩)O~" ); } } @AfterMethod public void tearDown(){ if (driver!= null ){ driver.quit(); } } }
正常運行后,這幾行代碼將會打開IE瀏覽器,然后轉跳到百度首頁。
并關閉IE瀏覽器。
?
(以上內容參考群共享某word資料,不知具體作者是誰哈~)
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
