无法使用 Nightwatch 单击模态中的元素

Can't click on element in modal using Nightwatch

我正在使用 Nightwatch 编写一些测试,我在测试的最后阶段有 1 个问题我无法解决。我有一个提交内容的按钮,然后当他们单击提交时,会弹出一个模式询问他们是否确定。我正在尝试单击 "Yes, I am sure",但 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')

单击 "Yes, I'm sure" 按钮(这不起作用)

.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()
});
getLocationInView('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,function() {
    this.pause(3000)
    .click('body > div.sweet-alert.hiddenField.showSweetAlert.visible > div.sa-button-container > div > button')
})