1.加入junit支持
创建一个项目,在项目的build path中选中add libraries 然后选中junit就行
2.加入selenium
(1)Chrome驱动下载:http://chromedriver.storage.googleapis.com/index.html 根据对应的谷歌版本下载
谷歌版本查看:打开谷歌浏览器,点击设置,点击关于Chrome,就可以看到对应版本
然后把安装包里的exe文件放到一个目录下我选择的是:C:\webDriver
(2)selenium驱动下载:http://selenium-release.storage.googleapis.com/index.html
选择对应版本:听说3.9版本还不错。选择:selenium.X.X.X.jar下载
找到eclipse.exe对应所在的文件,把对应的selenium jar包放到该目录下。
再在项目对应的build path 里点击 add external archives 添加jar包就行
(3)写自动化程序:
示例代码:
package selenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static void test(WebDriver driver)throws InterruptedException{
driver.get("https://www.bilibili.com/");
driver.findElement(By.xpath("//*[@id="primaryPageTab"]/ul/li[1]")).click();
}
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "c:\webDriver\chromedriver.exe");
WebDriver driver=new ChromeDriver();
try {
test(driver);
}catch(Exception e) {
e.printStackTrace();
}
}
}



