每周问答 执行 driver.findElements (By.name ().isEmpty () 方法-偶尔会出现页面存在该元素却无法获取的现象

日落。 · 2015年05月05日 · 最后由 日落。 回复于 2015年05月06日 · 33 次阅读

appium Server 版本: 1.3.4.1

代码如下:

String elementsNeedToFind = "autotest-IP-DVR";
driver.findElements(By.name(elementsNeedToFind)).isEmpty()

日志如下:

> info: --> POST /wd/hub/session/a0b028fb-1375-44cb-a988-d32adc5e149b/elements {"using":"name","value":"autotest-IP-DVR"}
> info: [debug] Waiting up to 2000ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding autotest-IP-DVR using NAME with the contextId:  multiple: true
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=autotest-IP-DVR, INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[TEXT=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[TEXT=autotest-IP-DVR, INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
> info: [debug] Waited for 114ms so far
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding autotest-IP-DVR using NAME with the contextId:  multiple: true
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=autotest-IP-DVR, INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[TEXT=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[TEXT=autotest-IP-DVR, INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
> info: [debug] Waited for 698ms so far
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding autotest-IP-DVR using NAME with the contextId:  multiple: true
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=autotest-IP-DVR, INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[TEXT=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[TEXT=autotest-IP-DVR, INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
> info: [debug] Waited for 1465ms so far
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding autotest-IP-DVR using NAME with the contextId:  multiple: true
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=autotest-IP-DVR, INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[TEXT=autotest-IP-DVR]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[TEXT=autotest-IP-DVR, INSTANCE=0]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
> info: [debug] Condition unmet after 2287ms. Timing out.

截图如下:

现象:执行的时候偶尔会出现无法定位到这个元素,结果 isEmpty() 为 true,但页面上这个元素是存在的。
求大神指点!!

共收到 2 条回复 时间 点赞

#1 楼 @beerbox 我是做了一个循环,循环三次都没发现,才失败的。。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册