selenium - 为什么守夜人找不到我的dom?

标签 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>

下面是守夜人代码。

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

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

✖ Timed out while waiting for element <#gwt-debug-MenuItem> to be visible for 5000 milliseconds.  - expected "visible" but got: "not visible"

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

最佳答案

看起来该元素并不是真正可见的。尝试使用 waitForElementPresent

等待它的出现
module.exports = {
  'Connection Test' : function (browser) {
    browser
      .url('file:///tmp/test.html')
      .waitForElementPresent("#gwt-debug-MenuItem", 5000)
      .pause(1000)
      .end();
  }
};

关于selenium - 为什么守夜人找不到我的dom?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41546915/

相关文章:

python - Selenium 从表元素中搜索数据

javascript - Selenium Web 驱动程序的文件上传功能无法通过 sendkeys 工作

javascript - 在 Nightwatch 中运行 "traditional"单元测试

javascript - 如何在 NightwatchJS 中对元素列表进行断言

php - 如何自动化浏览任务?

java - 用于 Selenium 测试的 Spring Security @WithMockUser

python - 无法在 google chrome 网页上找到元素

Selenium WebDriver HTTP 错误 : 403 Forbidden for Proxy RequestURI=/session

javascript - nightwatchjs - 如何检测隐藏的 html 元素?

javascript - 如何使用 Protractor 通过 CSS 代码单击元素?