【求助】app自动化过程,隐式等待和显示等待报错问题

环境:macOS,appium-1.19.1,selenium 3.141.0和 4.1.5

移动端型号:网易 mumu

移动端系统:android 6

问题复述:
问题 1,selenium 3.141.0 时,appium 初始化 driver,隐式等待报错。selenium 升级到 4.1.5,该问题消失,出现问题 2:显示等待使用presence_of_element_located()正常,visibility_of_element_located()则报错

问题一:
appium初始化在隐式等待报错,升级 selenium 版本到 4.1.5 后解决,但是想了解一下原因,已进行相关搜索。

代码

 def start(self, driver: WebDriver = None):
        if self._driver is None:
            caps = {}
            caps["platformName"] = "android"
            caps["deviceName"] = "emulator-5554"
            caps["appPackage"] = self._appPackage
            caps["appActivity"] = self._appActivity
            caps["noReset"] = True
            caps["skipDeviceInitialization"] = True
            caps["skipServerInstallation"] = True
            caps["chromedriverExecutable"] = "/Users/serenehoo/projects/chromedriver/chromedriver_66"
            self._driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
            self._driver.implicitly_wait(30)

        else:
            self._driver.start_activity(self._appPackage, self._appActivity)

        return self

报错信息:

    def setup(self):
>       self.main = App().start().main()

test_mail.py:10: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../page/base/app.py:33: in start
    self._driver.implicitly_wait(30)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <appium.webdriver.webdriver.WebDriver (session="c930e2f1-4772-4ba1-aa70-94484fa5b3c1")>
time_to_wait = 30

    def implicitly_wait(self, time_to_wait):
        """
        Sets a sticky timeout to implicitly wait for an element to be found,
           or a command to complete. This method only needs to be called one
           time per session. To set the timeout for calls to
           execute_async_script, see set_script_timeout.
    
        :Args:
         - time_to_wait: Amount of time to wait (in seconds)
    
        :Usage:
            driver.implicitly_wait(30)
        """
>       if self.w3c:
E       AttributeError: 'WebDriver' object has no attribute 'w3c'

log 文件
appium-问题 1.log (17.2 KB)

问题二:
基于问题 1,升级selenium版本到 4.1.5,隐式等待未报错,但显示等待若使用方法until(expected_conditions.visibility_of_element_located())报错,换成until(expected_conditions.presence_of_element_located())则执行通过

代码:

 def edit_mail(self):
        ele=(MobileBy.ACCESSIBILITY_ID,'写邮件')
        # 执行成功
        # WebDriverWait(self._driver,30).until(expected_conditions.presence_of_element_located(ele))
        # 这句执行报错
        WebDriverWait(self._driver,30).until(expected_conditions.visibility_of_element_located(ele))
        self.find(MobileBy.ACCESSIBILITY_ID,'写邮件').click()

报错信息:

FAILED
testcase/test_mail.py:14 (TestMail.test_mail)
self = <app_wework.testcase.test_mail.TestMail object at 0x7f9d8c8eed60>

    def test_mail(self):
>       self.main.goto_mail().edit_mail()

test_mail.py:16: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../page/mail/mail.py:17: in edit_mail
    WebDriverWait(self._driver,30).until(expected_conditions.visibility_of_element_located(ele))
../../venv/lib/python3.8/site-packages/selenium/webdriver/support/wait.py:78: in until
    value = method(self._driver)
../../venv/lib/python3.8/site-packages/selenium/webdriver/support/expected_conditions.py:125: in _predicate
    return _element_if_visible(driver.find_element(*locator))
../../venv/lib/python3.8/site-packages/selenium/webdriver/support/expected_conditions.py:149: in _element_if_visible
    return element if element.is_displayed() == visibility else False
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <appium.webdriver.webelement.WebElement (session="fd94225c-eb72-4d7a-93ef-e25327fee351", element="e2f34d29-673b-41f8-b588-33265c2f6e72")>

    def is_displayed(self) -> bool:
        """Whether the element is visible to a user.
    
        Override for Appium
        """
>       return self._execute(RemoteCommand.IS_ELEMENT_DISPLAYED)['value']
E       AttributeError: type object 'Command' has no attribute 'IS_ELEMENT_DISPLAYED'

../../venv/lib/python3.8/site-packages/appium/webdriver/webelement.py:81: AttributeError

log 文件:
appium-问题 2.log (30.9 KB)

selenium版本3.141.0匹配的appium-python-client版本是1.2.0,你的appium-python-client版本是多少的;如果是selenium4点多版本会去除一些方法,而且匹配的appium-python-client是2.1.2;如果这两个版本不匹配的话,其中的安装的一些包会冲突。这些坑我目前也没有踩完…还是用selenium版本3.141.0匹配的appium-python-client版本是1.2.0稳定一点

感谢老师~降了版本,改了 appium-python-client版本没有问题了。之前确实没有关注过这两个直接的匹配关系,非常感谢~!

关闭