欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
和我一起學(xué) Selenium WebDriver(7)
昨天我們已經(jīng)可以輕松移動(dòng)鼠標了,距離拖拽只有一步之遙。 其實(shí)這就是一層窗戶(hù)紙,捅破它就搞定了,之前做的操作可以說(shuō)都是單步操作:移動(dòng)鼠標、點(diǎn)擊頁(yè)面元素、彈出窗口等等;而拖拽操作就不行了,他需要一連串連貫的動(dòng)作配合起來(lái):mousedown、mousemove、mouseup,缺了哪個(gè)都不行,順序不對也不行。

【1、如何進(jìn)行拖拽】
    這時(shí)候我們就需要用到 org.openqa.selenium.interactions.Actions 這個(gè)類(lèi)了,它專(zhuān)門(mén)用來(lái)做動(dòng)作組合的。 Actions 中有若干方法,可以讓你很容易的生成 鼠標、按鍵的操作集合。
    例如: clickAndHold + moveToElement + release 就可以組合成一套拖拽的操作;
    詳細內容還請查看 Selenium 的 javadoc:http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html

     生成操作組合后,利用 build 方法可以得到一個(gè)有效的 Action 對象;最后使用 perform 方法執行就可以了。

    和昨天測試鼠標移動(dòng)的情況類(lèi)似,還是 FireFox 問(wèn)題最大, IE8 有小問(wèn)題, Chrome 測試最正常。

FireFox:使用 moveToElement 方法時(shí),效果同昨天使用 MoveToOffsetAction 情況類(lèi)似,xOffset、yOffset值無(wú)論如何設置,在頁(yè)面上得到的都是 指定的 頁(yè)面元素;
    另外,如果在不使用 moveToElement的時(shí)候就使用moveByOffset 很容易報錯:org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Element cannot be scrolled into view: (WARNING: The server did not provide any stacktrace information)

IE8: 使用 moveToElement 方法時(shí),如果用到了 xOffset、yOffset 參數,你會(huì )發(fā)現在 IE8中 計算的情況 和 Chrome 上不太一樣,貌似范圍會(huì )更大一些,因此導致如果設置為0, 0 時(shí),就不是你預期的結果了

測試代碼我分成了3個(gè)部分:
  • 觀(guān)察反復拖拽測試 1
   可以專(zhuān)門(mén)用來(lái)觀(guān)察 moveToElement 在不同瀏覽器下的情況

  • 觀(guān)察反復拖拽測試 2
   可以專(zhuān)門(mén)用來(lái)觀(guān)察 moveByOffset 在不同瀏覽器下的情況,FireFox 會(huì )報錯

  • 觀(guān)察系列操作測試
   可以專(zhuān)門(mén)用來(lái)觀(guān)察 多種組合操作 在 不同瀏覽器下的情況


    總之,對于鼠標移動(dòng)和拖拽的測試還是直接在 Chrome 下進(jìn)行就可以了吧;ie的只能略微參考;剩下的還是自己手動(dòng)來(lái)吧。。。。
    如果想在 IE 上正常測試,建議采用moveToElement(WebElement)+ moveByOffset(xOffset, yOffset); 避免直接使用 moveToElement(WebElement, xOffset, yOffset),同時(shí)還是要嚴格注意 xOffset 和 yOffset 的設置;這個(gè)需要根據自己的實(shí)際情況來(lái)調試了。

    學(xué)習了這些內容以后,對于 測試 zTree 這類(lèi)前端 js 插件來(lái)說(shuō)就足夠了,剩下的就努力干活兒吧。 貌似我是真用不上 Selenium 的 webdriver 了。。。

以下是測試代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package lesson07;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.HasInputDevices;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.MoveMouseAction;
import org.openqa.selenium.interactions.MoveToOffsetAction;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import util.Common;
public class ExampleForDrag  {
     
    static WebDriver driver;
     
    @BeforeClass
    public static void init() {
        System.out.println("init...");
        //用 Chrome
//      System.setProperty(
//              "webdriver.chrome.driver",
//              "E:\\BaiduWangPan\\百度網(wǎng)盤(pán)\\javascript\\Selenium WebDriver\\chromedriver_win_23.0.1240.0\\chromedriver.exe");
//      driver = new ChromeDriver();
         
        //用 IE
//      driver = new InternetExplorerDriver();
         
        //用 FireFox
        System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
        // 創(chuàng )建一個(gè) FireFox 的瀏覽器實(shí)例
        driver = new FirefoxDriver();
    }
     
    @Test
    public void test() {
        // 讓瀏覽器訪(fǎng)問(wèn) zTree Demo
        driver.get("http://www.ztree.me/v3/demo/cn/exedit/drag.html");
         
        // 等待 zTree 初始化完畢,Timeout 設置10秒
        try {
            (new WebDriverWait(driver, 10, 500)).until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver d) {
                    WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("return $('#treeDemo li').get(0);");
                    return element != null;
                }
            });
             
        } catch(Exception e) {
            e.printStackTrace();
        }
         
        //找到第一個(gè)根節點(diǎn)的子節點(diǎn)
        ((JavascriptExecutor)driver).executeScript("window.zTreeObj = $.fn.zTree.getZTreeObj('treeDemo');"
                + "window.zTreeNodeSrc = window.zTreeObj.getNodes()[0].children[0];");
         
        //獲取 需要拖拽的節點(diǎn)對象
        WebElement elementSrc = (WebElement) ((JavascriptExecutor)driver).executeScript("return $('#' + window.zTreeNodeSrc.tId + '_a').get(0)");
        //獲取 目標節點(diǎn)對象
        WebElement elementTarget = (WebElement) ((JavascriptExecutor)driver).executeScript("window.zTreeNodeTarget = window.zTreeNodeSrc.getNextNode().children[0]; return $('#' + window.zTreeNodeTarget.tId + '_a').get(0)");
        Actions actions = new Actions(driver);
        Action action;
        //觀(guān)察反復拖拽測試 1
//      actions.clickAndHold(elementSrc);
//      for (int i=0; i<500; i++) {
//          actions.moveToElement(elementTarget, i%100-50, i%50-20);
//      }
//      actions.release();
//      action = actions.build();
//      action.perform();
//     
//      Common.waitFor(10, driver);
        //觀(guān)察反復拖拽測試 2
//      actions.clickAndHold(elementSrc).moveToElement(elementTarget);
//      int x = 0, y = 0, dx=2, dy=2;
//      for (int i=0; i<500; i++) {
//          x+=2; y+=2;
//          if (x > 50) {
//              dx = -x;
//              x = 0;
//          } else {
//              dx = 2;
//          }
//          if (y > 150) {
//              dy = -y;
//              y = 0;
//          } else {
//              dy = 2;
//          }
//          actions.moveByOffset(dx, dy);
//      }
//      actions.release();
//      action = actions.build();
//      action.perform();
//      Common.waitFor(10, driver);
         
        //觀(guān)察系列操作測試
        System.out.println("移動(dòng)成為目標節點(diǎn)的 前一個(gè)節點(diǎn)");
        actions.clickAndHold(elementSrc).moveToElement(elementTarget, 60, 1).release();
        action = actions.build();
        action.perform();
         
        // 等待 10 秒
        Common.waitFor(10, driver);
         
        System.out.println("移動(dòng)成為目標節點(diǎn)的后一個(gè)節點(diǎn)");
        actions.clickAndHold(elementSrc).moveToElement(elementTarget, 60, 38).release();
        action = actions.build();
        action.perform();
         
        // 等待 10秒
        Common.waitFor(10, driver);
         
        System.out.println("移動(dòng)成為目標節點(diǎn)的子節點(diǎn)");
        actions.clickAndHold(elementSrc).moveToElement(elementTarget).release();
        action = actions.build();
        action.perform();
         
        // 等待 10秒
        Common.waitFor(10, driver);
        System.out.println("移動(dòng)成為目標節點(diǎn)下一個(gè)節點(diǎn)的子節點(diǎn)");
        actions.clickAndHold(elementSrc).moveToElement(elementTarget).moveByOffset(0, 20).release();
        action = actions.build();
        action.perform();
         
        // 等待 10秒
        Common.waitFor(10, driver);
         
    }
     
    @AfterClass
    public static void destory() {
        System.out.println("destory...");
        //關(guān)閉瀏覽器
        driver.quit();
    }
}
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Selenium2(webdirver)入門(mén)之環(huán)境搭建(Java版)
selenium webdriver 環(huán)境搭建–java
Selenium(五)——webdriver 之操作頁(yè)面元素
WebDriver拾級而上·之十 封裝與重用
Selenium WebDriver 之 PageObjects 模式 by Example
selenium web driver 實(shí)現截圖功能
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久