javascript - 等待 javascript 事件 WebDriver

标签 javascript selenium selenium-webdriver automated-tests bdd

我有一个用 angularJS 构建的菜单和子菜单。

每个菜单都有以下代码:

<a class="ng-scope" ng-click="irPara(item, $event)" ng-if="!item.heading" title="">

当我尝试点击子菜单的链接时,Selenium 抛出一个异常,指出元素不可点击,或者找不到元素。

我假设发生这种情况是因为我必须等待子菜单加载,如何在不使用 Thread.sleep() 的情况下等待加载此子菜单

谢谢

最佳答案

您可以使用显式等待。在 JavaScript 中变通:

driver.wait(function() {
    return driver.findElement(locator).isDisplayed();
}, 10);

这将等待最多 10 秒来显示元素。

关于javascript - 等待 javascript 事件 WebDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34993457/

相关文章:

javascript - 如何使用 MSE 在视频标签中播放 H.264 NAL 单元流?

javascript - 为 Google Adsense 找到预加载链接,但浏览器未使用

PHP : Carousel Bootstrap CSS

javascript - 是否内置选择器选项以使用 nightwatchjs 做出复杂的决策?

python - Selenium Python 的 http.client.RemoteDisconnected : Remote end closed connection without response error using driver. quit()

javascript - 带 Node 的简单用户登录验证模块

python - 在 pytest 中,如何判断测试是否失败? (从 "request"开始)

html - 通过地址模板点击链接

javascript - 运行 Nightwatch.js 测试时,如何获取当前运行测试的浏览器的名称?

java - 出现错误 - org.openqa.selenium.StaleElementReferenceException : stale element reference: element is not attached to the page document