您的位置:首页 > 其它

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

2017-01-04 15:38 507 查看


<!--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 类
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: