用获取tost的方式去获取并点击密码键盘上的元素,出现了报错?

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

菜鸟学飞ing

2018-08-05

代码
def get_Keypad_Number():
Keypad_Number_1 = ("xpath","//*[contains(@text,'3')]")
Number1 = WebDriverWait(driver,10,0.1).until(EC.presence_of_element_located(Keypad_Number_1))
Number1.click()

Appium--server的报错信息

[HTTP] <-- POST /wd/hub/session/dd525ec2-e2b7-4ef9-ae15-8ea58b5f700a/element 500 24 ms - 164
[HTTP] 
[HTTP] --> POST /wd/hub/session/dd525ec2-e2b7-4ef9-ae15-8ea58b5f700a/element
[HTTP] {"using":"xpath","value":"//*[contains(@text,'3')]","sessionId":"dd525ec2-e2b7-4ef9-ae15-8ea58b5f700a"}
[W3C] Calling AppiumDriver.findElement() with args: ["xpath","//*[contains(@text,'3')]","dd525ec2-e2b7-4ef9-ae15-8ea58b5f700a"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8206/wd/hub/session/61c727a2-1fec-4db0-a6a4-7ed294d0cd73/element] with body: {"strategy":"xpath","selector":"//*[contains(@text,'3')]","context":"","multiple":false}
[MJSONWP] Encountered internal error running command:  {"w3cStatus":400,"jsonwp":{"sessionId":"61c727a2-1fec-4db0-a6a4-7ed294d0cd73","status":7,"value":"An element could not be located on the page using the given search parameters."}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"sessionId":"61c727a2-1fec-4db0-a6a4-7ed294d0cd73","status":7,"value":"An element could not be located on the page using the given search parameters."}
[MJSONWP]     at JWProxy.proxy$ (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:152:13)
[MJSONWP]     at tryCatch (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[MJSONWP]     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
[MJSONWP]     at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
[MJSONWP]     at GeneratorFunctionPrototype.invoke (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[MJSONWP]     at
[MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[HTTP] <-- POST /wd/hub/session/dd525ec2-e2b7-4ef9-ae15-8ea58b5f700a/element 500 22 ms - 164
[HTTP]


控制台的报错信息

Traceback (most recent call last):
  File "E:\Appium\FXJC_Appium_Python\Start_Appium.py", line 118, in <module>
    login_new()
  File "E:\Appium\FXJC_Appium_Python\Start_Appium.py", line 107, in login_new
    get_Keypad_Number()
  File "E:\Appium\FXJC_Appium_Python\Start_Appium.py", line 84, in get_Keypad_Number
    Number1 = WebDriverWait(driver,10,0.1).until(EC.presence_of_element_located(Keypad_Number_1))
  File "C:\Python36\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

[Finished in 66.9s with exit code 1]

老师,因为我们APP的密码必须要用软件自带的数字键盘来进行输入,所以我就想用了你这个获取tost元素的方法去获取键盘上的按钮的元素。我在获取到这个键盘上的数字3的这个元素后,然后实现对它的点击,结果报错了。

1、这个为什么会报错呢?

2、有没有方法可以获取点击密码数字键盘上的元素呢?

求老师帮忙指点一二...


写回答

1回答

Mushishi

2018-08-07

你好,"An element could not be located on the page using the given search parameters 这个已经告诉你元素不存在。你的想法不错,但是tost和实际的弹出键盘不一样,这个时候你不能够那么操作,所以你需要做的就是不能用这个方法,如果自带键盘1、你可以尝试通过sendkeys来实现。2、 去获取你键盘的坐标,然后通过坐标实现,不过第二种是最好用,也是最能解决的,这个需要你自己去写方法,先获取屏幕,然后拿一个元素作为一个参考,再去解析键盘的大小,然后把键盘拆分多少个键盘格,然后记住每个键盘的坐标,然后去点击就好。第一种不能是不一定能够解决的。

0
4
Mushishi
回复
菜鸟学飞ing
567497910 这个是专属的群。这个之前再群里回答过,你可以讨论一下,之前有小伙伴做了,也是自定义键盘,必须通过手动点击才行,而且不能输入。
2018-08-09
共4条回复

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

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

1508 学习 · 1333 问题

查看课程