[英]Scrolling in Appium using Python
我想向下滾動屏幕,但似乎無法正確操作。 Appium的原始方式如下:
actions = TouchAction(driver)
actions.scroll_from_element(element, 10, 100)
actions.scroll(10, 100)
actions.perform()
我的代碼是:
actions = TouchAction(self.driver)
actions.scroll_from_element('com.android.dialer.dialers', x=90, y=1330)
actions.scroll(x=90, y=170)
actions.perform()
但是,我收到以下錯誤消息:
line 133, in test_app
scroll.scroll_from_element('com.android.dialer.dialers', x=90, y=1230)
AttributeError: 'TouchAction' object has no attribute 'scroll_from_element'
對我來說,使用滑動功能工作:
#swipe(startX, startY, endX, endY, duration)
self.driver.swipe(150, 400, 150, 200, 1000)
您很可能會收到錯誤消息,因為 appium-python 客戶端沒有scroll_from_element
函數。
滾動屏幕的第一種方法是找到 2 個元素,然后從一個滾動到另一個。
el1 = self.driver.find_element_by_accessibility_id(<your locator to scroll from>)
el2 = self.driver.find_element_by_accessibility_id('your locator to scroll to')
action = TouchAction(self.driver)
action.press(el1).move_to(el2).release().perform()
如果要移動到具有偏移量的元素,可以這樣做:
action.press(el1).move_to(el2, offsetX, offsetY).release().perform()
其中 offsetX、offsetY 代表偏移。
如果您的應用具有可滾動視圖,您可以使用 find+UIAutomator2 定位器滾動到所需元素:
targetElement = self.driver.find_element_by_android_uiautomator(
'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Element text").instance(0));')
當然,最好用uiselector().resourceid(elementId)
替換UiSelector().text("Element text")
uiselector().resourceid(elementId)
我建議檢查客戶端存儲庫中的官方功能測試作為工作示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.