4. 打開cmd命令窗口,切換到my_testng_test文件夾,敲入命令:mvn eclipse:eclipse 回車出現(xiàn)Build Success信息,則創(chuàng)建Webdriver項目成功。
5. 在eclipse中導(dǎo)入所建文件夾
6. 在my_testng_test項目下新建Source Folder - src, 新建package - org.openqa.selenium.example并在package “org.openqa.selenium.example”下新建
Class (修改使用Selenium官網(wǎng)上的例子)
<span style="font-family:SimSun;font-size:12px;">package org.openqa.selenium.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Selenium2Example {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin", "D:\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("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
</span>
運行即可。