为什么夜班人不能找到我的dom?

Zha*_* Yi 2 selenium selenium-webdriver nightwatch.js

我正在使用nightwatch进行集成测试,但未能找到我的dom元素之一.下面是我的HTML代码:

<body>
    <div style="position: absolute; overflow: hidden; height: 24px;">
        <div class="GPNWDJGEV" style="width: 24px; height: 24px;">
          </div>
        <div id="gwt-debug-MenuItem" style="width:100px;height:100px;">

        </div>
    </div>
</body>
Run Code Online (Sandbox Code Playgroud)

以下是夜班代码.

module.exports = {
  'Connection Test' : function (browser) {
    browser
      .url('file:///tmp/test.html')
      .waitForElementVisible("#gwt-debug-MenuItem", 5000)
      .pause(1000)
      .end();
  }
};
Run Code Online (Sandbox Code Playgroud)

运行此测试用例时出现以下错误:

? Timed out while waiting for element <#gwt-debug-MenuItem> to be visible for 5000 milliseconds.  - expected "visible" but got: "not visible"
Run Code Online (Sandbox Code Playgroud)

我能够找到其他dom元素但未能找到这个#gwt-debug-MenuItem.这段代码有什么问题?

Guy*_*Guy 6

看起来元素不是真的可见.尝试等待它的存在而不是waitForElementPresent

module.exports = {
  'Connection Test' : function (browser) {
    browser
      .url('file:///tmp/test.html')
      .waitForElementPresent("#gwt-debug-MenuItem", 5000)
      .pause(1000)
      .end();
  }
};
Run Code Online (Sandbox Code Playgroud)