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 類

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM