# -*- 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
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:
> 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:
> 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:
> 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.