Reputation: 211
I am writing some tests using Nightwatch, and I am at the very end of my test and I have 1 issue I can't figure out. I have a button to submit something, and then when they click submit, a modal pops up asking them if they are sure. I am trying to click "Yes, I am sure" but Nightwatch isn't finding the element. Below is my code.
Click on Submit Button (This works)
.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')
Click on "Yes, I'm sure" button (This doesn't work)
.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')
I just get an error saying it is unable to find the element.
Upvotes: 1
Views: 1947
Reputation: 1
This also worked for me...
.acceptAlert()
https://v09.nightwatchjs.org/api/acceptAlert.html
Upvotes: 0
Reputation: 1
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')
})
Upvotes: 0
Reputation: 479
Try this
.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()
});
Upvotes: 2