51Testing软件测试论坛

标题: 执行 driver.findElements (By.name ().isEmpty () 方法-偶尔会出现页面存在该元素... [打印本页]

作者: 测试积点老人    时间: 2019-8-22 11:08
标题: 执行 driver.findElements (By.name ().isEmpty () 方法-偶尔会出现页面存在该元素...
执行 driver.findElements (By.name ().isEmpty () 方法-偶尔会出现页面存在该元素却无法获取的现象

appium Server版本: 1.3.4.1

代码如下:

  1. String elementsNeedToFind = "autotest-IP-DVR";
  2. driver.findElements(By.name(elementsNeedToFind)).isEmpty()
复制代码

日志如下:

  1. > info: --> POST /wd/hub/session/a0b028fb-1375-44cb-a988-d32adc5e149b/elements {"using":"name","value":"autotest-IP-DVR"}
  2. > info: [debug] Waiting up to 2000ms for condition
  3. > info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
  4. > info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
  5. > info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
  6. > info: [debug] [BOOTSTRAP] [debug] Got command action: find
  7. > info: [debug] [BOOTSTRAP] [debug] Finding autotest-IP-DVR using NAME with the contextId:  multiple: true
  8. > info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=autotest-IP-DVR]
  9. > info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=autotest-IP-DVR]
  10. > info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
  11. > info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=autotest-IP-DVR, INSTANCE=0]
  12. > info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=autotest-IP-DVR]
  13. > info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[TEXT=autotest-IP-DVR]
  14. > info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
  15. > info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[TEXT=autotest-IP-DVR, INSTANCE=0]
  16. > info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
  17. > info: [debug] Waited for 114ms so far
  18. > info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
  19. > info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
  20. > info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
  21. > info: [debug] [BOOTSTRAP] [debug] Got command action: find
  22. > info: [debug] [BOOTSTRAP] [debug] Finding autotest-IP-DVR using NAME with the contextId:  multiple: true
  23. > info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=autotest-IP-DVR]
  24. > info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=autotest-IP-DVR]
  25. > info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
  26. > info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=autotest-IP-DVR, INSTANCE=0]
  27. > info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=autotest-IP-DVR]
  28. > info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[TEXT=autotest-IP-DVR]
  29. > info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
  30. > info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[TEXT=autotest-IP-DVR, INSTANCE=0]
  31. > info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
  32. > info: [debug] Waited for 698ms so far
  33. > info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
  34. > info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
  35. > info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
  36. > info: [debug] [BOOTSTRAP] [debug] Got command action: find
  37. > info: [debug] [BOOTSTRAP] [debug] Finding autotest-IP-DVR using NAME with the contextId:  multiple: true
  38. > info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=autotest-IP-DVR]
  39. > info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=autotest-IP-DVR]
  40. > info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
  41. > info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=autotest-IP-DVR, INSTANCE=0]
  42. > info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=autotest-IP-DVR]
  43. > info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[TEXT=autotest-IP-DVR]
  44. > info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
  45. > info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[TEXT=autotest-IP-DVR, INSTANCE=0]
  46. > info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
  47. > info: [debug] Waited for 1465ms so far
  48. > info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}]
  49. > info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"autotest-IP-DVR","context":"","multiple":true}}
  50. > info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
  51. > info: [debug] [BOOTSTRAP] [debug] Got command action: find
  52. > info: [debug] [BOOTSTRAP] [debug] Finding autotest-IP-DVR using NAME with the contextId:  multiple: true
  53. > info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=autotest-IP-DVR]
  54. > info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=autotest-IP-DVR]
  55. > info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
  56. > info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=autotest-IP-DVR, INSTANCE=0]
  57. > info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=autotest-IP-DVR]
  58. > info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[TEXT=autotest-IP-DVR]
  59. > info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
  60. > info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[TEXT=autotest-IP-DVR, INSTANCE=0]
  61. > info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
  62. > info: [debug] Condition unmet after 2287ms. Timing out.
复制代码

截图如下:

[attach]126222[/attach]

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




作者: qqq911    时间: 2019-8-23 10:38
加个等待时间
作者: libingyu135    时间: 2019-8-23 11:43
不知
作者: litingting0214    时间: 2019-8-23 11:45
可能是上一个页面还没有加载完,直接获取页面上的东西会获取不到,加一个2s的等待时间,应该可以解决
作者: jingzizx    时间: 2019-8-23 12:25
等待是否出现




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2