获取不到toast,提示selenium.common.exceptions.TimeoutException: Message:

来源:1-19 如何获取tost元素

慕雪7554485

2018-05-14

# -*- coding:utf-8 -*-
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as Ec
import time
capabilites ={
    "platformName":"Android",
    "automationName":"UiAutomator2",
    "deviceName":"I76PBE4D45EADQSS",
    "app":"D:\\mukewang.apk"
    }
driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",capabilites)
time.sleep(20)

def get_toast():
    toast_element=("xpath","//*[contains(@text,'请输入密码')]")
    WebDriverWait(driver,30,0.01).until(Ec.presence_of_element_located(toast_element)
   
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("cn.com.open.mooc:id/account_edit")').send_keys('11223344')
time.sleep(2)
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("cn.com.open.mooc:id/login_lable")').click()
get_toast()

运行后提示

Traceback (most recent call last):
  File "D:\Program Files (x86)\eclipse\workspace\AppiumPython\case\start_appium.py", line 122, in <module>
    get_toast() 
  File "D:\Program Files (x86)\eclipse\workspace\AppiumPython\case\start_appium.py", line 98, in get_toast
    WebDriverWait(driver,30,0.01).until(Ec.presence_of_element_located(toast_element))   
  File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

Appium端提示

 info: --> POST /wd/hub/session/016083e1-5a97-4349-9d38-03faaf772e7f/element {"using":"xpath","value":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","sessionId":"016083e1-5a97-4349-9d38-03faaf772e7f"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":32,"value":"javax.xml.transform.TransformerException: Expected ,, but found: '璇疯緭鍏ュ瘑鐮?"}
> info: [debug] Condition unmet after 24ms. Timing out.
> info: [debug] Responding to client with error: {"status":32,"value":{"message":"Argument was an invalid selector (e.g. XPath/CSS).","origValue":"javax.xml.transform.TransformerException: Expected ,, but found: '璇疯緭鍏ュ瘑鐮?"},"sessionId":"016083e1-5a97-4349-9d38-03faaf772e7f"}
> info: <-- POST /wd/hub/session/016083e1-5a97-4349-9d38-03faaf772e7f/element 500 26.454 ms - 234 
> info: --> POST /wd/hub/session/016083e1-5a97-4349-9d38-03faaf772e7f/element {"using":"xpath","value":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","sessionId":"016083e1-5a97-4349-9d38-03faaf772e7f"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":32,"value":"javax.xml.transform.TransformerException: Expected ,, but found: '璇疯緭鍏ュ瘑鐮?"}
> info: [debug] Condition unmet after 25ms. Timing out.
> info: [debug] Responding to client with error: {"status":32,"value":{"message":"Argument was an invalid selector (e.g. XPath/CSS).","origValue":"javax.xml.transform.TransformerException: Expected ,, but found: '璇疯緭鍏ュ瘑鐮?"},"sessionId":"016083e1-5a97-4349-9d38-03faaf772e7f"}
> info: <-- POST /wd/hub/session/016083e1-5a97-4349-9d38-03faaf772e7f/element 500 28.577 ms - 234 
> info: --> POST /wd/hub/session/016083e1-5a97-4349-9d38-03faaf772e7f/element {"using":"xpath","value":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","sessionId":"016083e1-5a97-4349-9d38-03faaf772e7f"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":32,"value":"javax.xml.transform.TransformerException: Expected ,, but found: '璇疯緭鍏ュ瘑鐮?"}
> info: [debug] Condition unmet after 13ms. Timing out.
> info: [debug] Responding to client with error: {"status":32,"value":{"message":"Argument was an invalid selector (e.g. XPath/CSS).","origValue":"javax.xml.transform.TransformerException: Expected ,, but found: '璇疯緭鍏ュ瘑鐮?"},"sessionId":"016083e1-5a97-4349-9d38-03faaf772e7f"}
> info: <-- POST /wd/hub/session/016083e1-5a97-4349-9d38-03faaf772e7f/element 500 15.537 ms - 234 
> info: --> POST /wd/hub/session/016083e1-5a97-4349-9d38-03faaf772e7f/element {"using":"xpath","value":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","sessionId":"016083e1-5a97-4349-9d38-03faaf772e7f"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)]","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)] using XPATH with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":32,"value":"javax.xml.transform.TransformerException: Expected ,, but found: '璇疯緭鍏ュ瘑鐮?"}
> info: [debug] Condition unmet after 14ms. Timing out.



写回答

2回答

慕姐1291937

2019-03-22

你好,请问下您的问题解决没呢?我也遇到了一样的问题,怎么弄都解决不了

0
6
Mushishi
回复
慕姐1291937
你需要启动代码中去用uiautomator2 配置一下才行。
2019-03-25
共6条回复

Mushishi

2018-05-15

你好,你看: info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,u'璇疯緭鍏ュ瘑鐮?)] using XPATH with the contextId:  multiple: false 提示已经没找到了,这个你去找个乱码,你处理一下

0
3
慕运维2948618
回复
慕数据2282311
外层单引号,里层用双引号试试?
2018-07-21
共3条回复

Python主讲移动端自动化测试框架Appium

APP自动化基础知识、po模型、关键字模型、服务自动化、持续集成

1508 学习 · 1333 问题

查看课程