• 使用Uiautomator语法定位元素时,报错此元素不是一个字符串 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()
    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

  • 相关阅读:
    信息的概念
    信息管理学基础
    第一章关键术语
    企业的转变
    国外的信息系统概念
    管理信息系统的基本功能
    人机交互设计-评价输入法-课下作业
    《构建之法》一
    27日进度
    26号进度
  • 原文地址:https://www.cnblogs.com/yushengaqingzhijiao/p/15241665.html
Copyright © 2020-2023  润新知