If you close the window when using ModalWindows in wicket, you get this message:
"Reloading this page will cause modal window to disappear"
Is there a way to configure this to show OTHER message? (for i18n purposes)
Thanks a lot!!
Manuel
You can dismiss the modal window message by setting the Javascript variable Wicket.Window.unloadConfirmation to false and provide your own handler on window.onbeforeunload.
So you have to set the following Javascript in your pages :
Wicket.Window.unloadConfirmation = false;
window.onbeforeunload=function(){
return I18n("yourI18nKey");
}
That is a browser dependent message and not a wicket message.
I believe Chrome and IE will show the one you pointed out.
Firefox 4 shows "This page is asking you to confirm that you want to leave - data you have entered may not be saved.".
I found out another, quite common way to get that warning when developing a modal view: if you happen to get this confirmation box by accident, it may be an indication of error in your code (Exception on log) and fixing the error also fixes the show of this message.
Good to note is that the confirm box is only an indication of error, not the cause of error itself. The error is elsewhere.
Source: http://ttlnews.blogspot.fi/2010/07/lessons-learned-wicket-spring-hibernate.html
Related
I want to close my Android application with a method, but it should be shown a custom message (which I define for myself).
everything I found yet was "How to close my application" and I got more than 10 ways to close my application but I haven't found a way to set a custom message.
At the moment if my app crashes something like this appears:
[APPNAME] has been stopped
I want something like this
Congratulations! You found a bug, please submit it.
Is there even a way to do that? All methods I found just closed all activities or just forced an unresolveable error.
I don't think you need some code from me, but if you do, tell me.
(Language should be java and javascript/jQuery should be avoided)
You could try making a static stop method:
public static void stop(String message) {
Log.d(message);
System.exit(0);
}
I have searched for this issue, and nothing that I've seen seems to work. I am currently trying to enter a username and password into an authentication box in Chrome, and I can't find a good way to do it in Selenium. The problem comes from the fact that running the "click" method on a webelement in Selenium effectively stops all execution until the authentication box has been dealt with. I've tried three approaches:
Before clicking on a webelement, create a new thread. In that thread, run
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
Then run alert.authenticateUsing(new UserAndPassword("-ssqatest", "Sqa7-3$t"));
The problem with this is that alertIsPresent doesn't actually work in Chrome. I can confirm this by putting a print statement right after it, and it will never run, as it throws the error "cannot determine loading status". It works in Firefox, however, which leads me to the second attempt:
Doing it the same way as above, but in Firefox
This doesn't work because while the alert is detected properly, the line right after to authenticateUsing throws a selenium.Unsupportedcommandexception.
Directly typing in "https://username:password#url.com" into the Firefox browser after detecting the alert
This doesn't work because I can't use Selenium to get the URL of the page, since the webdriver was instantiated on the original thread, which got stopped during the authentication popup. I would prefer not to re-instantiate a new session just to get the URL of the page.
At this point, the only other method I can think of is to use java's Robot class, but I also would prefer not to do this, as it becomes quite messy with needing to manually have the robot have a keypress and keyrelease for each character.
What would be the best approach?
Thanks
You dont need to re-instantiate the thread. Unless im missing something you can go with #3 and just use switchTo() to change windows. Something like this:
Set<String> windowHandles = driver.getWindowHandles();
for(String handle : windowHandles) {
driver.switchTo().window(handle);
if(driver.getTitle().equals(NEW_WINDOW_TITLE)) {
return;
}
}
In play framework, every time you get an Internal Server Error (500) in production mode, the browser shows a web page with
Oops, an error occured, This exception has been logged with id XXXX
I would like to customize the error message (or at least translate it to spanish), keeping the error id that makes it easier to look for in the application log.
I've tried to configure an error page in the Global settings in JAVA like this:
public Promise<Result> onError(RequestHeader request, Throwable t) {
return Promise.<Result>pure(internalServerError(
views.html.error.render(t)
));
}
Where I've a view named error.scala.html.
It is not working right now, it does not show any errors, just ignores it. Also with this alternative, I don't know how to display the error id.
I appreciate any suggestions, thanks a lot.
Is your Global class in the root package? That's a quite common mistake and also the reason why it is ignored.
In my program, I get the following javascript alert
I am able to switch to this alert. I am able to get the text and click the OK and Cancel buttons. The issue I am having is when using assertequals to verify the alert text. I am using the below code
String Test = driver.switchTo().alert().getText();
System.out.println(Test);
Assert.assertEquals(Test, "You are sharing your report with \"Limited Overall-10000 \".\n\nThis will share your report with \"179\" people. Continue?");
System.out.println correctly prints the text of the alert box. However, I get the below error when trying to use assertequals. Its strange because these same steps work for other javascript alerts on the page.
org.openqa.selenium.WebDriverException: [JavaScript Error: "e is null" {file: "file:///C:/Users/IBM_AD~1/AppData/Local/Temp/anonymous2086351268768311654webdriver-profile/extensions/fxdriver#googlecode.com/components/command_processor.js" line: 7716}]
I was getting the same error.
Turns out I was closing the webdriver before I had dismissed the alert box.
Closing/clicking the alert and then closing the driver fixed the issue.
You've run into a bug in Selenium:
https://code.google.com/p/selenium/issues/detail?id=7977
https://code.google.com/p/selenium/issues/detail?id=3544
(Yes, the two bug reports are related.)
There's a problem in Selenium whereby if you try to terminate the driver while an alert is active, you'll get e is null or a number of other error messages. As Lawrence Tierney mentioned, you should make sure that the alert is closed before terminating the driver. Your code should do this whether or not the assert is successful.
I want to handle alerts Using HTMLUnitDriver in java. I am using following code to handle the alerts using firefox driver and it is working fine.
Alert alert = driver.switchTo().alert();
alert.accept();
but HTMLUnitDriver is giving error like
java.lang.UnsupportedOperationException: alert()
How to handle there alert box ?
If you don't need to check whether the alert actually appears, I would recommend changing the behavior of the JavaScript alert() method to log a message instead:
JavascriptExecutor javascriptExecutor = (JavascriptExecutor) webDriver;
javascriptExecutor.executeScript("window.alert = function(message){ console.log(message); };" +
"window.confirm = function(message){ console.log(message); return true; };");
Then you can skip HtmlUnitDriver.switchTo().alert().accept() in your code.
Note: This method won't work if the alert appears on the initial page load since Selenium waits for the page to be loaded before interacting with it. So the above JavaScript will be executed too late.
As of HtmlUnitDriver version 2.25, HtmlUnitDriver.switchTo().alert().accept() no longer throws an UnsupportedOperationException(). However, accept() appears to do nothing except confirm that the alert is present. Since the alert cannot be dismissed, turning off alerts using the above method is probably the best/only solution. If you must test alerts with HtmlUnitDriver, you may need two separate tests---one for checking that the alert appears and another for checking that the browser behaves correctly when the alert is disabled.
If you desperately need alert handing and you are okay with building from source, alert handling has been implemented in the master branch of HtmlUnitDriver. I'm not sure when it will be included in a release, though.
The request to implement the alert-API in the HTMLUnitDriver has been placed several years ago. This is the link:
https://code.google.com/p/selenium/issues/detail?id=1105&q=alert%28%29&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary
As this seems to be a hard nut to crack, you have to think about some tricks to circumvent the modal dialogs (alert, confirm, ...) in JavaScript. At least until they have implemented the alert-API.
The tricks to prevent the modal dialogs to show consists of adding additional JavaScript to your Selenium script. For example change the callback-functions to avoid the alert box.
Also, be aware it is impossible to close/cancel/confirm modal dialogs with JavaScript itself. That's the reason why you should prevent them to show. This is due to security reasons.
Until the alert-API has been implemented, this is the only way to handle it with HtmlUnitDriver.