请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

toast定位元素报错:element not found

老师,我有个元素,在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不能定位吗?我该用什么方法定位到这个元素?

正在回答

2回答

Mushishi 2019-11-06 22:02:55

你好,这个是tost吗?应该是你们自定义的炭层,你看一下点击厚的元素能在结构化中展示出来吗

0 回复 有任何疑惑可以回复我~
提问者 连枝 2019-11-06 22:06:50

老师 我也不确定是不是tost,我用uiautomator没法聚焦选中这个内容,元素结构里面也没有显示。这种情况下我该怎么去检查这个东西存在

0 回复 有任何疑惑可以回复我~
  • 如果你用的android 5之上手机获取不到,而且这个不是常驻的,你问一下你们开发采用的什么形式
    回复 有任何疑惑可以回复我~ 2019-11-07 09:04:57
  • 提问者 连枝 回复 Mushishi #2
    开发说这是控件自带的
    回复 有任何疑惑可以回复我~ 2019-11-11 15:15:47
  • Mushishi 回复 提问者 连枝 #3
    那就是一个控件,不是tost,你就直接findelement
    回复 有任何疑惑可以回复我~ 2019-11-11 19:44:31
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信