<!--test.html-->
<html>
<head>
<title>Set Timeout</title>
<script>
</script>
</head>
<body>
<input type="text" name="lastname">
<input id = "alert" value = "alert" type = "button" onclick = "alert('歡迎!請按確認繼續!');"/>
<input id = "confirm" value = "confirm" type = "button" onclick = "confirm('確定嗎?');"/>
<input id = "prompt" value = "prompt" type = "button" onclick = "var name = prompt('請輸入你的名字:','請輸入你的名字'); document.write(name) "/>
</body>
</html>
public static void main(String[] args) throws InterruptedException, IOException {
//定義一個前綴文件夾
String string="非常有才華,有能力,有技術!!!!!!!";
int i=0;
WebDriver dr = new FirefoxDriver();
String url = "file:///C:/Users/leixiaojiang/Desktop/test.html";
dr.get(url);
//新建一個action
Actions action=new Actions(dr);
//操作
WebElement element=dr.findElement(By.name("lastname"));
WebElement element1=dr.findElement(By.id("alert"));
while (i<10000)
{
action.sendKeys(element,string+i).perform();
i++;
}
action.moveToElement(element1);
action.click().perform();
}
//拖放的組合操作
Action dragAndDrop = builder.clickAndHold(someElement).moveToElement(otherElement).release(otherElement).build().perform();
其他鼠標或鍵盤操作方法可以具體看一下API 里面的
org.openqa.selenium.interactions.Actions 類