您的位置:首页 > 其它

selenium 2.44安装测试教程(附全程免费资料软件包下载)

2016-08-31 20:46 513 查看
休息时间接触了一下selenium,这个用于动态网页技术的自动化实现有很强的功能,我写这篇文章的时候也是初学阶段,但是最后是要到外文网站找教程才可以让程序跑起来,国内的感觉说的不足以让我完美的安装,于是想写一篇教程方便希望学习web自动化技术的各位同学作为参考(本文提到的安装包都会在末尾链接给出免费下载)

因为我还没完全搞懂chrome的调试,所以只给出Firefox浏览器的调试

直入主题:

进入这个selenium官方下载网页

http://www.seleniumhq.org/download/

现在讲最基本的java开发,所以大家按照官网导航是应该在这里找自己的语言下载api



但是因为selenium3是测试版本,我用的是2.44版本

然后下载selenium-java-2.44.0.zip

2.44对应的是Firefox 33版本的浏览器,版本别错了。

浏览器后面也会提供下载

然后把selenium-java-2.44.0.zip解压后的所有jar包都导入eclipse(这个应该不用教了吧。。)

然后跑这一段程序

package test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class SeleniumConsoleExample {
public static void main(String[] args) {
// Create HTML Unit Driver - this is the build in Selenium client
WebDriver driver = new HtmlUnitDriver();
// go to url
driver.get("http://www.baidu.com");
//driver.get("http://www.pbc.gov.cn");
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}


运行结果:

Page title is: 百度一下,你就知道


好了,说明最简单的开发端口已经正常运行了。

现在我们安装一下Firefox,安装到默认路径。

然后跑一段代码:

package test;
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.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class test2 {

public static void main(String[] args) throws Exception {
// create a Firefox Web Driver
WebDriver driver = new FirefoxDriver();

// open the browser and go to JavaTutorial Network Website
driver.get("https://javatutorial.net");
// find the search button on the page
WebElement searchButton = driver.findElement(By
.className("search-submit"));
// create an action handler
Actions actions = new Actions(driver);
// use the action handler to move the cursor to given element
actions.moveToElement(searchButton).perform();
// wait until the search field is presented on the webpage and create an
// element
WebElement searchField = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.name("s")));
// puts the text "java" into the search field
searchField.sendKeys("java");
// submit the search (submit the form)
searchField.submit();
// wait 5 seconds and close the browser
Thread.sleep(5000);
driver.quit();
}

}


可以正常打开Firefox说明配置正常,可以开始学习selenium其他技术了。(完)

下载链接:

http://download.csdn.net/detail/charchunchiu/9618255
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: