【Selenium WebDriver自动化测试实例】清除文本框内容!

**package navigateBack;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.apache.http.util.Asserts;
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.testng.annotations.AfterClass;
public class ClearInputBox {
WebDriver driver;
String url=“http://www.baidu.com”;
@Test
public void test() throws InterruptedException {
driver.get(url);
Thread.sleep(3000);
WebElement element = driver.findElement(By.id(“kw”));
element.sendKeys(“郭向前”);
element.clear();
Thread.sleep(3000);
element.sendKeys(“今日新鲜事”);
driver.findElement(By.id(“su”)).click();
Thread.sleep(3000);
WebElement element2 = driver.findElement(By.xpath("//div[@class=‘op_exactqa_answer_s’]"));
Actions actions= new Actions(driver);
actions.doubleClick().build().perform();
Thread.sleep(3000);

}
@BeforeClass
public void beforeClass() {
System.setProperty(“webdriver.firefox.bin”, “C:\Program Files (x86)\Mozilla Firefox\firefox.exe”);
driver=new FirefoxDriver();
}
@AfterClass
public void afterClass() {
driver.quit();
}
}**

你可能感兴趣的:(自动化测试实例)