When one scenario is done, the page refreshes (in the website there is a javascript modal implemented before refreshing the page which asks the user "Are you sure you want to leave the page?"). I need to confirm that modal. But when I create the step for that, I always get this error:
Then User clicks "Leave this page" button in the popup at online reg form
no alert open
(Session info: chrome=35.0.1916.114)
and the code
And(/^User clicks "([^"]*)" button in the popup at online reg form$/) do |button|
wait = Selenium::WebDriver::Wait.new
alert = wait.until { page.driver.browser.switch_to.alert }
alert.accept
end
Does anyone know how to handle this?
You need to override the confirm dialogue method in javascript to always return true
page.evaluate_script('window.confirm = function() { return true; }')
use this line before the line of code that triggers the dialogue to popup and it will always accept it no more steps needed :)
Related
When user click on browser back button, user will see a alert message for that I am using below code.
window.onbeforeunload = function () { return "If you want to go back to previous page Please use Previous step Button in below"; };
But in the code I have written "If you want to go back to previous page Please use Previous Step Button in below". This message is not displaying in alert box,instead of that message it is showing another message:
.
How can I display my own message in the alert box?
You will need to put javascript/jquery code you want to use on a handler for beforeunload event
window.addEventListener("beforeunload", function (event) {
//your code goes here. Create modal window or whatever you need
});
Let's say I have an update page in HTML5 and if the user edited a field, I want to show a pop-up whenever the user will exit the page (by clicking on another link) without clicking the update button. The pop-up will confirm if the user wants to save his edits or if the user declined, simply continue on the link he clicked before. How to achieve this in HTML5/JavaScript? Is there any function that preempts redirects? Thanks.
Use the onbeforeunload event.
Check out the demo: onbeforeunload Demo
JS code:
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
</script>
I have an alert which appears to state that data has been submitted. Problem is thought that when the alert appears it comes up with this dialogue in the alert "Prevent this page from creating additional dialogues" or something like that.
How can I get rid of this from the alert? If I can't get rid of it then is there are way I can get something like a prompt box or a confirmation box which only has an 'OK' button to appear because I don't want like the "Prevent this page from creating additional dialogues" message.
Below is my code:
function submitform()
{
var fieldvalue = $("#QandA").val();
$.post("insertQuestion.php", $("#QandA").serialize() ,function(data){
alert("Your Details for this Session has been submitted");
var QandAO = document.getElementById("QandA");
QandAO.submit();
});
}
You can't stop this from happening. Good browsers provide the option to prevent scripts from spawning alerts because alerts are often annoying. If this option could be revoked by the script, what has been gained?
The reason why you get it for that alert and not for the other one is because this alert will be fired programmaticly at the difference to be initiated by the user action.
open firebug
alert('hello')
Everytime this alert is called it show a conventional alert without the checkbox
setInterval(function(){
alert('hello')
}, 500)
The first alert is normal the second one got the checkbox and allow you to prevent future alert because as steve says "good" browser can kind of understand something and have built in "supposedly helper"
Steve is right when he says that the message can not be removed but you can only control how the alert is open.
Perso I will not recommend you to use native alert because while the alert is open all the code on the page remain halted meaning nothing happen behind the popup. This can be annoying depending on your app.
i have a jsp file .whenever user closes the screen a pop up with custom message and two custom buttons ( continue and cancel ) should appear .by clicking continue button u should go to another page .and cancel button to stay on the same page .......plz help me out how cud these be achieved ..
Is there a way to change default message I am getting 'Are you sure you want to navigate away from this page?' and then 'Press OK to continue, or Cancel to stay on the Current page.' Can I only display 'my message' in between this two messages?
I am using below javascript codes:
<script type="text/javascript">
function beforeClose()
{
return "my mssage...";
}
window.onbeforeunload=beforeClose;
</script>
check out this thread for your answer
How can I override the OnBeforeUnload dialog and replace it with my own?
I need to prompt the user to a site usability survey when the user navigate away from the site or try to close the site window. For example, when the user closes the window of my site, I want to show a prompt to say "do you want to take a survey?" , if the user clicks yet, open a new window with the survey link.
Is there a way in GWT to achieve that?
I have tried using
Windows.addWindowCLosingHandler
but that only gave me the ability to set a message to ask if the user want to stay on the site or now using ClosingEvent event , event.setMessage("sure?");
thanks
You can use window.onunload but that will be called whenever the user changes the page
Also see here: How to catch user leaving a page and cancelling it
Use the unload method on the body:
<body onUnload="unloadFunction(); return false;">
Then something like this for your js:
function unloadFunction()
{
if (confirm("Would you like to take our servey?"))
{
window.location.href = 'location_of_your_survey'
}
return false;
}