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 閱讀(1915) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動化測試學習

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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 普兰店市| 保山市| 虞城县| 桃江县| 横峰县| 任丘市| 儋州市| 通辽市| 凤城市| 乐平市| 浦城县| 靖江市| 吉安县| 宜春市| 七台河市| 东阳市| 南阳市| 浦东新区| 平和县| 沁源县| 扶风县| 梁平县| 偏关县| 拉萨市| 普陀区| 灵山县| 金门县| 都匀市| 新巴尔虎左旗| 阿鲁科尔沁旗| 聂荣县| 琼中| 双鸭山市| 攀枝花市| 彰化县| 江都市| 富阳市| 分宜县| 马鞍山市| 平原县| 随州市|