测试积点老人 发表于 2019-8-22 11:08:41

执行 driver.findElements (By.name ().isEmpty () 方法-偶尔会出现页面存在该元素...

执行 driver.findElements (By.name ().isEmpty () 方法-偶尔会出现页面存在该元素却无法获取的现象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: Waiting up to 2000ms for condition
> info: Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
> info: Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
> info: Got command of type ACTION
> info: Got command action: find
> info: Finding autotest-IP-DVR using NAME with the contextId:multiple: true
> info: Using: UiSelector
> info: getElements selector:UiSelector
> info: Element[] is null: (0)
> info: getElements tmp selector:UiSelector
> info: Using: UiSelector
> info: getElements selector:UiSelector
> info: Element[] is null: (0)
> info: getElements tmp selector:UiSelector
> info: Returning result: {"value":[],"status":0}
> info: Waited for 114ms so far
> info: Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
> info: Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
> info: Got command of type ACTION
> info: Got command action: find
> info: Finding autotest-IP-DVR using NAME with the contextId:multiple: true
> info: Using: UiSelector
> info: getElements selector:UiSelector
> info: Element[] is null: (0)
> info: getElements tmp selector:UiSelector
> info: Using: UiSelector
> info: getElements selector:UiSelector
> info: Element[] is null: (0)
> info: getElements tmp selector:UiSelector
> info: Returning result: {"value":[],"status":0}
> info: Waited for 698ms so far
> info: Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
> info: Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
> info: Got command of type ACTION
> info: Got command action: find
> info: Finding autotest-IP-DVR using NAME with the contextId:multiple: true
> info: Using: UiSelector
> info: getElements selector:UiSelector
> info: Element[] is null: (0)
> info: getElements tmp selector:UiSelector
> info: Using: UiSelector
> info: getElements selector:UiSelector
> info: Element[] is null: (0)
> info: getElements tmp selector:UiSelector
> info: Returning result: {"value":[],"status":0}
> info: Waited for 1465ms so far
> info: Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
> info: Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
> info: Got command of type ACTION
> info: Got command action: find
> info: Finding autotest-IP-DVR using NAME with the contextId:multiple: true
> info: Using: UiSelector
> info: getElements selector:UiSelector
> info: Element[] is null: (0)
> info: getElements tmp selector:UiSelector
> info: Using: UiSelector
> info: getElements selector:UiSelector
> info: Element[] is null: (0)
> info: getElements tmp selector:UiSelector
> info: Returning result: {"value":[],"status":0}
> info: Condition unmet after 2287ms. Timing out.截图如下:现象:执行的时候偶尔会出现无法定位到这个元素,结果isEmpty()为true,但页面上这个元素是存在的。
求大神指点!!

qqq911 发表于 2019-8-23 10:38:29

加个等待时间

libingyu135 发表于 2019-8-23 11:43:52

:(不知

litingting0214 发表于 2019-8-23 11:45:15

可能是上一个页面还没有加载完,直接获取页面上的东西会获取不到,加一个2s的等待时间,应该可以解决

jingzizx 发表于 2019-8-23 12:25:31

等待是否出现
页: [1]
查看完整版本: 执行 driver.findElements (By.name ().isEmpty () 方法-偶尔会出现页面存在该元素...