——- android培训、java培训、期待与您交流! ——-
一个简单的Selenium Webdriver测试程序
package com.cxy.controller;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestBaidu {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*新建一个WebDriver 的对象,但是new 的是FirefoxDriver的驱动。后续再介绍java基础知识会普及一下类和对象之间的关系。*/
WebDriver dr = new FirefoxDriver();
//用火狐打开网站
dr.get("http://www.baidu.com");
/*是自动化过程中最常用的一个方法,在页面中寻找一个元素。其中传进入的参数就是你所定位到的元素, */
//找到文本框填入文本
dr.findElement(By.id("kw")).sendKeys("hello Selenium");
//找到按钮点击
dr.findElement(By.id("su")).click();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dr.quit();
}
}
很简单的一个程序,完全是在模拟正常的浏览器操作。