qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          Selenium2.0功能測試之如何使用Action類來模擬交互

           Selenium提供了一個強大的用于真實的模擬用戶交互的一個類----Actions,這個類提共了一系列的API供模擬交互:
            keyDown : 用于模擬按鍵被按下
            keyUp : 用于模擬按鍵松開
            doubleClick : 用于模擬雙擊
            clickAndHold : 用于模擬鼠標左鍵點住不放開
            release : 用于模擬松開鼠標,與clickAndHold相配合
            moveToElement : 將鼠標移動至元素的中間位置
            contextClick : 模擬鼠標右鍵點擊
            dragAndDrop : 拖拽
            這里由于測試頁面的限制我就只舉一個contextClick的例子:
          package org.coderinfo.demo;
          import org.openqa.selenium.By;
          import org.openqa.selenium.WebDriver;
          import org.openqa.selenium.WebElement;
          import org.openqa.selenium.chrome.ChromeDriver;
          import org.openqa.selenium.interactions.Actions;
          public class ActionDemo {
          private static final String URL = "http://www.baidu.com";
          /**
          * @author Coderinfo
          * @E-mail coderinfo@163.com
          */
          public static void main(String[] args) throws InterruptedException {
          WebDriver driver = new ChromeDriver();
          driver.manage().window().maximize(); //最大化瀏覽器界面
          driver.get(URL); //訪問度娘首頁。
          Thread.sleep(2000); //等待頁面加載
          WebElement input = driver.findElement(By.id("kw"));  //獲取百度搜索框
          Actions ac = new Actions(driver);  // 為driver 加載 actions
          ac.contextClick(input).perform();  // 在百度搜索框上點擊右鍵
          Thread.sleep(10000);
          driver.quit();
          }
          }
          相關文章
          Selenium2.0功能測試之文件上傳(Java版)

          posted on 2013-10-31 11:31 順其自然EVO 閱讀(1919) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動化測試學習

          <2013年10月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 彭水| 千阳县| 东乡族自治县| 曲麻莱县| 安平县| 南雄市| 通辽市| 金堂县| 德清县| 鹤壁市| 综艺| 泊头市| 榆树市| 富锦市| 德江县| 玉溪市| 自治县| 罗平县| 台北市| 古蔺县| 兴义市| 盐城市| 大厂| 眉山市| 罗甸县| 千阳县| 凤凰县| 赣州市| 马关县| 绵竹市| 红桥区| 上杭县| SHOW| 瑞金市| 华蓥市| 双柏县| 龙胜| 和硕县| 澳门| 手游| 嘉禾县|