Appium滑动元素时,报错:
selenium.common.exceptions.InvalidElementStateException: Message: Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.
在使用Appium进行swipe()滑动操作时,提示:
selenium.common.exceptions.InvalidElementStateException: Message: Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.
解决方案
InvalidElementStateException,通常与元素状态有关,所以在滑动之前,要等待元素变得可见和可交互。
因此,只需操作滑动元素之前,添加等待即可。
def test_swipe_to(): from driver.appium.webdriver import Webdriver appium_server_url = 'http://localhost:4723' capabilities = { "platformName": "Android", "automationName": "uiautomator2", "deviceName": "127.0.0.1:62001", "app": "D:\\resources\\imooc.apk", } driver = Webdriver(command_executor=appium_server_url, capabilities=capabilities) time.sleep(3) # 等待页面加载完成之后,再滑动页面 driver.swipe_to('left', n=2) driver.swipe_to('right', n=3)