老师,我有个元素,在uiautomator上无法聚焦
场景是不输入userid,输入密码,点击登录,用户名输入框马上就会显示“请填写”。
我的代码如下:
import sys
sys.path.append('/Users/zy/PycharmProjects/Appiumpython')
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from util.get_by_local import GetByLocal
def get_tost():
get_by_local=GetByLocal(driver)
# get_by_local.get_element('login_element','userid').send_keys('-')
get_by_local.get_element('login_element','password').send_keys('1234')
get_by_local.get_element('login_element','btn_login').click()
tost_element=("xpath","//*[contains(@text,'请填写')]")
WebDriverWait(driver,10,0.1).until(EC.presence_of_element_located(tost_element))
driver=get_driver()
get_tost()
报错:
[HTTP] {"using":"xpath","value":"//*[contains(@text,'请填写')]"}
[debug] [W3C (62434e95)] Calling AppiumDriver.findElement() with args: ["xpath","//*[contains(@text,'请填写')]","62434e95-f80c-457a-b97c-b8bcd0e947ed"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [WD Proxy] Matched '/element' to command name 'findElement'
[debug] [WD Proxy] Proxying [POST /element] to [POST http://localhost:8201/wd/hub/session/72f32ed7-05f2-4f47-80e1-d2cb2c13776d/element] with body: {"strategy":"xpath","selector":"//*[contains(@text,'请填写')]","context":"","multiple":false}
[WD Proxy] Got an unexpected response with status 404: {"sessionId":"72f32ed7-05f2-4f47-80e1-d2cb2c13776d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:102)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:72)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerCon...
[debug] [W3C] Matched W3C error code 'no such element' to NoSuchElementError
[debug] [W3C (62434e95)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[debug] [W3C (62434e95)] at AndroidUiautomator2Driver.findElOrEls (/usr/local/lib/node_modules/appium/node_modules/_appium-android-driver@4.20.1@appium-android-driver/lib/commands/find.js:75:11)
[HTTP] <-- POST /wd/hub/session/62434e95-f80c-457a-b97c-b8bcd0e947ed/element 404 525 ms - 417
老师,这个元素用toast不能定位吗?我该用什么方法定位到这个元素?