Hi, I have a web application that uses this component and I'm responsible for the automated tests. I have an issue in an alert that confirms a exclusion of a record. Selenium runs too fast and when the alert popsup it clicks very fast in the "OK" button to confirm the deletion. But for some reason it seems that the function behind this button is not called and the record is not deleted.
If I add a delay in the execution it works as expected.
Has anybody experiencing this problem?
Have you sync the moment that selenium do the click with the DOMContentLoaded event?
sweetAlert take some time to be fully loaded. You should wait until DOMContentLoaded (or $(document).ready()) is called to do anything.
@estivalet about 'If I add a delay in the execution it works as expected', would you like to tell me how to add the delay? I am encountering the problem these days, and I can not fix it. I am very glad to find that you have solution. Please kindly share it with me. Thank you!
I have described my similar problem in protractor resp, https://github.com/angular/protractor/issues/2770
Maybe this can help you.
http://stackoverflow.com/questions/15122864/selenium-wait-until-document-is-ready
https://gist.github.com/double16/e3dfa7ec496264f11648
I use a selenium like and its javascript, so i have access to the javascript events.
Can you add a timer? Wait for a few seconds before executing the code. Try this and tell us if the problem still exist.
As far as I can see, by looking at the code, this is how this library is supposed to work.
sweetalert performs a 500ms fadeIn when opening the modal.
During this time the OK/Cancel buttons will not run the callback function, it will close the modal instead.
An unexpected/confusing behaviour according to me.
sweetalert will add the class visible when the animation has finished.
Using Capybara for testing you could use the following:
within ".sweet-alert.visible" do
...
end
@sundling, you just saved me a real headache, thanks! :+1:
I am testing a web app that uses sweet alert. My automation framework is in selenium + Java + TestNG. The driver runs too fast to catch the alert and I am getting NoAlertPresentException. If I add wait, I get TimeoutException.
Has anyone come across this issue and is able to resolve it?
I got it to work this way.
within ".sweet-alert.visible" do
find('button.confirm').trigger('click')
end
Sorry for such a long delay. In SweetAlert 2.0, there should no longer be a delay for the buttons' actions. Please read the upgrade guide
Most helpful comment
As far as I can see, by looking at the code, this is how this library is supposed to work.
sweetalert performs a 500ms fadeIn when opening the modal.
During this time the OK/Cancel buttons will not run the callback function, it will close the modal instead.
An unexpected/confusing behaviour according to me.
sweetalert will add the class
visiblewhen the animation has finished.Using Capybara for testing you could use the following: