最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Appium中scroll和drag_and_drop根據(jù)元素位置滑動

 更新時間:2022年02月15日 15:21:26   作者:測試之路king  
本文主要介紹了Appium中scroll和drag_and_drop根據(jù)元素位置滑動,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

背景

我們在操作APP應(yīng)用時,有些需要從一個元素滑動到另外一個元素時,這時候我們無法確定坐標,所以swipe 根據(jù)坐標滑動方式就無法使用了,如下圖:從 課堂直播 上滑到 直播公開課 位置

在這里插入圖片描述


這時候我們就需要使用其他滑動方式,我們想到可以根據(jù)元素進行滑動,Appium 里面根據(jù)元素來進行滑動的方式主要方法為 scrolldrag_and_drop

scroll 介紹

說明

從一個元素滾動到另一個元素,只能是兩個元素之間的滑動。

方法詳情

def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration: Optional[int] = None) -> T:
        """Scrolls from one element to another

        Args:
            origin_el: the element from which to being scrolling
            destination_el: the element to scroll to
            duration: a duration after pressing originalEl and move the element to destinationEl.
                Default is 600 ms for W3C spec. Zero for MJSONWP.

        Usage:
            driver.scroll(el1, el2)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        """

        # XCUITest x W3C spec has no duration by default in server side
        if self.w3c and duration is None:
            duration = 600

        action = TouchAction(self)
        if duration is None:
            action.press(origin_el).move_to(destination_el).release().perform()
        else:
            action.press(origin_el).wait(duration).move_to(destination_el).release().perform()
        return self

參數(shù):

  • origin_el - 要滾動的起始元素
  • destination_el - 要滾動到的結(jié)束元素
  • duration - 持續(xù)時間,單位毫秒,默認為 600 ms

操作場景

  • 進入網(wǎng)易云首頁
  • 從課堂直播滑動到直播公開課位置

關(guān)鍵代碼實現(xiàn)

# 定位到課堂直播元素
el1 = driver.find_element(AppiumBy.XPATH, "http://*[@text='課堂直播']").click()

# 定位到直播公開課元素
el2 = driver.find_element(AppiumBy.XPATH, "http://*[@text='直播公開課']").click()

# 執(zhí)?滑動操作
driver.scroll(el1,el2)

說明

操作過程有 慣性,需要添加duration參數(shù),參數(shù)值越大,慣性越小。

drag_and_drop 介紹

說明

從一個元素滑動到另一個元素,第二個元素代替第一個元素原本屏幕上的位置。

方法詳情

def drag_and_drop(self: T, origin_el: WebElement, destination_el: WebElement) -> T:
        """Drag the origin element to the destination element

        Args:
            origin_el: the element to drag
            destination_el: the element to drag to

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        """
        action = TouchAction(self)
        action.long_press(origin_el).move_to(destination_el).release().perform()
        return self

參數(shù):

  • origin_el - 要滑動頁面的起始元素
  • destination_el - 要滑動頁面到結(jié)束元素

操作場景

  • 進入網(wǎng)易云首頁
  • 從課堂直播滑動到直播公開課位置

關(guān)鍵代碼實現(xiàn)

# 定位到課堂直播元素
el1 = driver.find_element(AppiumBy.XPATH, "http://*[@text='課堂直播']").click()

# 定位到直播公開課元素
el2 = driver.find_element(AppiumBy.XPATH, "http://*[@text='直播公開課']").click()

# 執(zhí)?滑動操作
driver.drag_and_drop(el1,el2)

說明

不能設(shè)置持續(xù)時間,沒有慣性

滑動和拖拽使用場景選擇

滑動和拖拽無非就是考慮是否具有“慣性”,以及傳遞的參數(shù)是“元素”還是“坐標”。

  • scroll:有 “慣性” ,傳入 “元素”,可以通過設(shè)置duration參數(shù)來進行控制慣性大小
  • drag_and_drop:無 “慣性” ,傳入 “元素”
  • swipe:有 “慣性” ,傳入 “坐標”,可以通過設(shè)置duration參數(shù)來進行控制慣性大小

說明: 添加duration參數(shù),參數(shù)值越大,慣性越小

到此這篇關(guān)于Appium中scroll和drag_and_drop根據(jù)元素位置滑動的文章就介紹到這了,更多相關(guān)Appium 元素滑動內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

沂南县| 永新县| 吉林省| 银川市| 桃园市| 托克逊县| 台东市| 万全县| 蒙自县| 盐亭县| 贵港市| 赞皇县| 新蔡县| 金秀| 电白县| 全南县| 成武县| 隆昌县| 霍城县| 永定县| 瑞丽市| 陇西县| 阿克陶县| 玉田县| 南投县| 博乐市| 铜梁县| 宜良县| 宁南县| 平果县| 蓝山县| 兴业县| 平泉县| 沙洋县| 桑植县| 双城市| 中西区| 荥经县| 西贡区| 浦东新区| 金寨县|