import time from appium import webdriver des = { "platformName": "Android", "platformVersion": "8.1.0", "deviceName": "vivo x20", "appPackage": "com.ibox.calculators", "appActivity": "com.ibox.calculators.CalculatorActivity", "udid": "c6c8c4ce", "noReset": True, "unicodeKeyboard": True, "resetKeyboard": True, } driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', des) driver.find_element_by_android_uiautomator("text('9')").click()
Traceback (most recent call last): File "C:/Users/admin/PycharmProjects/Appiunm_UI/adb_demo1/demo_04hunhe.py", line 27, in <module> driver.find_element_by_android_uiautomator("text('9')").click() File "C:UsersadminAppDataLocalProgramsPythonPython37-32libsite-packagesappiumwebdriverextensionssearch_contextandroid.py", line 147, in find_element_by_android_uiautomator return self.find_element(by=MobileBy.ANDROID_UIAUTOMATOR, value=uia_string) File "C:UsersadminAppDataLocalProgramsPythonPython37-32libsite-packagesappiumwebdriverwebdriver.py", line 283, in find_element return self.execute(RemoteCommand.FIND_ELEMENT, {'using': by, 'value': value})['value'] File "C:UsersadminAppDataLocalProgramsPythonPython37-32libsite-packagesseleniumwebdriver emotewebdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:UsersadminAppDataLocalProgramsPythonPython37-32libsite-packagesappiumwebdrivererrorhandler.py", line 31, in check_response raise wde File "C:UsersadminAppDataLocalProgramsPythonPython37-32libsite-packagesappiumwebdrivererrorhandler.py", line 26, in check_response super().check_response(response) File "C:UsersadminAppDataLocalProgramsPythonPython37-32libsite-packagesseleniumwebdriver emoteerrorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSelectorException: Message: Could not parse selector expression `new UiSelector().text('9')`: `UiSelector` doesn't have suitable method `text` with arguments ['9']: Could not parse selector expression `new UiSelector().text('9')`: '9' is not a string
后来查阅资料发现
需要将里面的括号变成双引号,外面的括号变成单引号才能进行识别
import time from appium import webdriver des = { "platformName": "Android", "platformVersion": "8.1.0", "deviceName": "vivo x20", "appPackage": "com.ibox.calculators", "appActivity": "com.ibox.calculators.CalculatorActivity", "udid": "c6c8c4ce", "noReset": True, "unicodeKeyboard": True, "resetKeyboard": True, } driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', des)
# 单双引号惹的祸
driver.find_element_by_android_uiautomator("text('9')").click()
https://blog.csdn.net/qq544649790/article/details/83960311?ops_request_misc=&request_id=&biz_id=102&utm_term=UiSelector%20%E6%89%A7%E8%A1%8Cnew%20UiSelector().&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-6-83960311.first_rank_v2_pc_rank_v29&spm=1018.2226.3001.4187