import unittest
from time import sleep
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.by import By
# 打开相册
capabilities = {}
capabilities['platformName'] = 'Android'
capabilities['automationName'] = 'uiautomator2'
capabilities['deviceName'] = 'Android'
capabilities['appPackage'] = 'com.android.settings'
capabilities['appActivity'] = '.Settings'
capabilities['language'] = 'en'
capabilities['locale'] = 'US'
appium_server_url = 'http://localhost:4723'
class TestAppium(unittest.TestCase):
def setUp(self) -> None:
# 获取driver
self.driver = webdriver.Remote(appium_server_url,capabilities)
self.driver.implicitly_wait(30)
def tearDown(self) -> None:
if self.driver:
# 退出程序
sleep(2)
self.driver.quit()
def test_find_battery(self) -> None:
# 创建touchaction对象
el = self.driver.find_element(By.XPATH, '//*[@text="Battery"]')
TouchAction(self.driver).tap(el).perform()
if __name__ == '__main__':
unittest.main()
里面的tap怎么不能使用了,写法正常,但运行起来的时侯,会显示报错,无法出现对应的效果,求解决
会显示下面的错误信息
"C:\tools\python 38\python.exe" "C:/tools/pycharm/PyCharm 2024.1.4/plugins/python/helpers/pycharm/_jb_unittest_runner.py" --target test_appium_tap.TestAppium
Testing started at 下午3:41 ...
Launching unittests with arguments python -m unittest test_appium_tap.TestAppium in C:\Users\TopOn\Desktop\test_appium
C:\tools\python 38\lib\site-packages\appium\webdriver\webdriver.py:273: DeprecationWarning: desired_capabilities has been deprecated, please pass in an Options object with options kwarg
super().__init__(
C:\tools\python 38\lib\site-packages\selenium\webdriver\remote\remote_connection.py:441: DeprecationWarning: HTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPResponse.headers.get(name, default).
if resp.getheader('Content-Type'):
C:\tools\python 38\lib\site-packages\selenium\webdriver\remote\remote_connection.py:442: DeprecationWarning: HTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPResponse.headers.get(name, default).
content_type = resp.getheader('Content-Type').split(';')
[Deprecated] 'TouchAction' action is deprecated. Please use W3C actions instead.
Error
Traceback (most recent call last):
File "C:\Users\TopOn\Desktop\test_appium\test_appium_tap.py", line 36, in test_find_battery
TouchAction(self.driver).tap(el).perform()
File "C:\tools\python 38\lib\site-packages\appium\webdriver\common\touch_action.py", line 171, in perform
self._driver.execute(Command.TOUCH_ACTION, params)
File "C:\tools\python 38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
self.error_handler.check_response(response)
File "C:\tools\python 38\lib\site-packages\appium\webdriver\errorhandler.py", line 31, in check_response
raise wde
File "C:\tools\python 38\lib\site-packages\appium\webdriver\errorhandler.py", line 26, in check_response
super().check_response(response)
File "C:\tools\python 38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
Stacktrace:
io.appium.uiautomator2.common.exceptions.UnknownCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:84)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:764)
Ran 1 test in 15.333s
FAILED (errors=1)
进程已结束,退出代码为 1