• 好像是因为找不到则会先选中中间那个,所以会打开中间那个的页面,有没有办法不点击呢?

  • 谢谢!

  • 图像元素识别类的定位方法是什么?

  • 打算换一个验证点,选择了重新发送倒计时的按钮,但是发现,正在倒计时的按钮(动态),定位好像特别慢。这是为什么呢

  • 是的!我觉得可能有这方面的原因,但是不知道咋办。

  • 我试过了,//android.widget.Toast[@text='发送成功']//android.widget.Toast[contains(@text,'发送成功')],其他的都可以,但是就那条 toast 不能捕捉到。

    根据 #10 @grace_zhang 10 楼提出的方法,试过 By.CLASSNAME 以及 By.XPATH(toast_loc = (By.XPATH, "//android.widget.Toast")以及 10 楼提到的方法都试了),By.CLASSNAME 所有的都捕捉不到,但是(By.XPATH, "//*[@class='android.widget.toast']").text也是那一条 “发送成功 toast” 捕捉不到

  • 好的,我试试,谢谢大家 @grace_zhang @xiaoj

  • appium 获取 toast 不是只能通过 xpath 或者 uiautomator 吗,后者好像比前者更慢。

  • 补充: 我在WebDriverWait(self.driver, 10, 0.01).until(lambda x: x.find_element(*(By.XPATH, '//*[contains(@text,\'{}\')]'.format("发送成功"))).text)前面截图,都是可以看到 toast 的,但是一获取不到 toast, 显示错误如下:

    Traceback (most recent call last):
      File "F:\lsj\Python\lib\unittest\case.py", line 60, in testPartExecutor
        yield
      File "F:\lsj\Python\lib\unittest\case.py", line 676, in run
        self._callTestMethod(testMethod)
      File "F:\lsj\Python\lib\unittest\case.py", line 633, in _callTestMethod
        method()
      File "F:\lsj\Python\lib\site-packages\ddt.py", line 182, in wrapper
        return func(self, *args, **kwargs)
      File "C:\Users\Administrator\PycharmProjects\\common\base_case.py", line 26, in wrapper
        raise err
      File "C:\Users\Administrator\PycharmProjects\\common\base_case.py", line 21, in wrapper
        func(self, *args, **kwargs)
      File "C:\Users\Administrator\PycharmProjects\\test_cases\test_sms_login.py", line 62, in test_login_01_success
        toast = self.driver.find_element(*(By.XPATH, "//*[contains(@text,'{}')]".format(check))).text
      File "F:\lsj\Python\lib\site-packages\appium\webdriver\webdriver.py", line 279, in find_element
        return self.execute(RemoteCommand.FIND_ELEMENT, {
      File "C:\Users\Administrator\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
        self.error_handler.check_response(response)
      File "F:\lsj\Python\lib\site-packages\appium\webdriver\errorhandler.py", line 31, in check_response
        raise wde
      File "F:\lsj\Python\lib\site-packages\appium\webdriver\errorhandler.py", line 26, in check_response
        super().check_response(response)
      File "C:\Users\Administrator\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
    
  • 有三秒,但是不知道为啥我捕捉不到