windows7 selenium2+java 搭建

來源:互聯網
上載者:User

標籤: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 搭建

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.