## 问题描述:Appium 的touchAction滑动操作,轨迹上是能看到滑动的,但是实际上只是坐标滑动了,页面没有进行真正的滑动。
- 环境:window10、appium-desktop(1.15.1版本)、java version “1.8.0_144”
- 移动端型号:网易mumu-oppo R11s
- 移动端系统:Android 6.0
- 问题复述:Appium 的touchAction滑动操作,轨迹上是能看到滑动的,但是实际上只是坐标滑动了,页面没有进行真正的滑动。
相关日志
无,程序运行通过,没有任何报错
尝试解决方案
方案一:换其他页面,也不能滑动
方案二:使用self.driver.swipe()也不能滑动
方案三:使用long_press也不能滑动
注:用鼠标在页面上是可以正常滑动的
相关代码
import pytest
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
class TestDW:
def setup(self):
desire_caps = {}
desire_caps[‘platformName’] = ‘android’
desire_caps[‘platformVersion’] = ‘6.0’
desire_caps[‘deviceName’] = ‘127.0.0.1:7555’
desire_caps[‘appPackage’] = ‘com.xueqiu.android’
desire_caps[‘appActivity’] = ‘.view.WelcomeActivityAlias’
desire_caps[‘noReset’] = ‘true’
# desire_caps[‘dontStopAppOnReset’] = ‘true’
desire_caps[‘unicodeheyBoard’] = ‘true’
desire_caps[‘reseKeyBoard’] = ‘true’
self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desire_caps)
self.driver.implicitly_wait(5)
def teardown(self):
self.driver.back()
self.driver.back()
self.driver.quit()
@pytest.mark.skip()
def test_search(self):
element = self.driver.find_element_by_id('com.xueqiu.android:id/home_search')
# 元素是否可用
search_element = element.is_enabled()
print(element.text)
print(element.location)
print(element.size)
if search_element == True:
element.click()
self.driver.find_element_by_id('com.xueqiu.android:id/search_input_text').send_keys('阿里巴巴')
element_search = self.driver.find_element_by_xpath("//*[@resource-id='com.xueqiu.android:id/name'and@text='阿里巴巴']")
element_display = element_search.get_attribute('displayed')
print(element_display)
if element_display == 'true':
print('搜索成功')
else:
print('搜索失败')
def test_touchaction(self):
action = TouchAction(self.driver)
# 获取当前window的像素
window_rect = self.driver.get_window_rect()
print(window_rect)
width = window_rect['width']
height = window_rect['height']
x = int(width/2)
y_start = int(height * 4/5)
y_end = int(height * 1/5)
print(x, y_start, y_end)
action.press(x=x, y=y_start).wait(200).move_to(x=x, y=y_end).release().perform()
if name == ‘main’:
pytest.main()