什么是selenium
一套软件工具,用来支持不同的自动化测试方法
开源软件:可以根据需要来增加重构工具的某些功能
跨平台:linux , windows, mac
核心功能就是可以在多个浏览器上进行自动化测试(Chrom,Opera,Windows phone,Firefox等)
支持多种编程语言
目前已经被google , 百度, 腾讯等公司广泛使用
能够实现类似商业工具的大部分功能,并且还实现了商业工具不能支持的功能
代码演示:
public static void test() throws InterruptedException{
System.setProperty("webdriver.firefox.marionette", "C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//实现窗口最大化
driver.manage().window().maximize();
//打开百度首页
driver.get("https://www.baidu.com");
//通过ID,找到文本输入框
WebElement shurukuang = driver.findElement(By.id("kw"));
//设置输入框的内容
shurukuang.sendKeys("战狼2");
//通过ID,找到搜索按钮
WebElement tijiao = driver.findElement(By.id("su"));
//点击搜索按钮
tijiao.click();
//关闭浏览器
driver.close();
}
jar包下载地址:http://docs.seleniumhq.org/download/
百度网盘下载地址:链接:http://pan.baidu.com/s/1o7AlLYM 密码:ax8u
驱动下载地址:https://github.com/mozilla/geckodriver/releases/tag/v0.9.0
驱动百度网盘地址:链接:http://pan.baidu.com/s/1pLDhR6r 密码:pmjh
注意:
1:如果你用的jar包是3点几的,一定要下载驱动,驱动地址在已经提供了。否则会报错这个错
The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html