selenium 使用action进行鼠标,键盘操作


<!--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 类
上一篇:zz:NETCONF协议详解


下一篇:autolayout高度动态改变的一些体会