node.js - 无法使用 Nightwatch 单击模式中的元素

标签 node.js nightwatch.js

我正在使用 Nightwatch 编写一些测试,我的测试已接近尾声,但有 1 个问题我无法解决。我有一个提交某些内容的按钮,然后当他们单击“提交”时,会弹出一个模式,询问他们是否确定。我尝试单击“是的,我确定”,但 Nightwatch 未找到该元素。下面是我的代码。

单击“提交”按钮(有效)

.getLocationInView('#objective-content-intro > div > div > div > div:nth-child(4) > div > div:nth-child(8) > div > div > a')
.assert.visible('#objective-content-intro > div > div > div > div:nth-child(4) > div > div:nth-child(8) > div > div > a')
.click('#objective-content-intro > div > div > div > div:nth-child(4) > div > div:nth-child(8) > div > div > a')

点击“是的,我确定”按钮(这不起作用)

.getLocationInView('body > div.sweet-alert.hiddenField.showSweetAlert.visible > div.sa-button-container > div > button')
.assert.visible('body > div.sweet-alert.hiddenField.showSweetAlert.visible > div.sa-button-container > div > button')
.waitForElementPresent('body > div.sweet-alert.hiddenField.showSweetAlert.visible > div.sa-button-container > div > button', 3000, 'Click on \"Yes, submit it!\"')
.pause(3000)
.click('body > div.sweet-alert.hiddenField.showSweetAlert.visible > div.sa-button-container > div > button')

我刚刚收到一条错误消息,指出无法找到该元素。

最佳答案

试试这个

.waitForElementPresent('#location > of > modal',20000, 'Some message here to show while running test')
.pause(1000)
.execute(function(){
    document.querySelector('body > div.sweet-alert.hiddenField.showSweetAlert.visible > div.sa-button-container > div > button').click()
});

关于node.js - 无法使用 Nightwatch 单击模式中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46244012/

相关文章:

node.js - 在主程序之前在 lambda 中加载 S3 文件

node.js - 在 Nightwatch 命令队列中使用 REST 客户端

javascript - 带有 Chromedriver 的 Nightwatch 在断言后不会退出

javascript - 如何使用 nightwatch.js 中的链接文本单击链接

javascript - 如何组合多个 this.expect 语句

javascript - 将 PDF 二进制数据编码为 base64 不适用于 NodeJS

javascript - 连接到 twitter api 时 Node.js 套接字挂断错误

javascript - 使用 Node 显示 SQL 值

node.js - DynamoDB.putItem 函数未使用 sls 命令保存项目

javascript - 选择框选项是可见还是隐藏?