I am a new to this. I am working on WindowTester.I could not open a new discussion page or I would tag it as Windowtester
I am having difficulty of closing down windows native dialog box after pull down menu. The code is,
ui.click(new PullDownMenuItemLocator("Save Control ", new ViewLocator("com.SOAGateway.control.views.SOAGView")));
After choosing one of the option from the menu, a dialog box appear which is native window dialog.
I would like to cancel it but it is not working.
I tried different things such as,
a)
ui.click(new PullDownMenuItemLocator("Save Control ", new ViewLocator("com.SOAGateway.control.views.SOAGView")));
Display display = new Display();
if (shell != null) shell.dispose();
b)
Display display = new Display();
ui.click(new PullDownMenuItemLocator("Save Control ", new ViewLocator("com.SOAGateway.control.views.SOAGView")));
display.dispose();
But nothing is working.
Is there any idea how could I sort out this problem.
Thanks.
Interaction with native Dialogs is very limited in Windowtester.
However, you should be able to cancel a native dialog in Windows with the following line of code:
ui.keyClick(WT.ESC);
SWTBOT can't handle native dialogs - see http://wiki.eclipse.org/SWTBot/FAQ#How_do_I_use_SWTBot_to_test_native_dialogs_.28File_Dialogs.2C_Color_Dialogs.2C_etc.29.3F
Related
In my application I have a main window and a utility popup dialog that is shown when the user clicks on a menu item. My issue is that if another program (say firefox) is opened over the java application, this obviously hides the java application. This is OK - but when the user then clicks on my java application again, only the main window is shown - the utility popup dialog is still hidden under firefox. I would like to design it such that when the user interacts with the main window in any way the utility popup dialog is also brought to the front.
I've tried adding a MouseInputListener to the main frame to bring the utility dialog to the front but this also transfers focus to it, which I don't want.
private MouseInputAdapter onWindowClick = new MouseInputAdapter() {
#Override
public void mousePressed(MouseEvent e) {
if (scheduleDialog != null)
scheduleDialog.toFront(); // the utility dialog
}
};
the utility popup dialog is still hidden
When the dialog is created you need to specify the main window as the owner of the dialog.
Then when you click on the icon for the window, the dialog will display as well.
Read the JDialog API for the proper constructor to use.
I have a program that runs in the CLI, but uses a JOptionPane in order to display a popup menu to alert the user of an event. I have noticed that when the showMessageDialog method is called, the resulting popup menu does not focus automatically.
Is there a way to request focus for the popup dialog box? I have tried calling requestFocus on the JOptionPane, but to no avail.
Here is some sample code.
System.out.println("Backing up...");
//backUp();
Component frame = null;
JOptionPane jop = new JOptionPane();
jop.showMessageDialog(frame, "Backup complete. Ready for encryption.");
I apologize if this is a repost, but I haven't been able to find a working answer so far.
Create a JDialog and make a call to setAlwaysOnTop passing true.
JOptionPane jop = new JOptionPane();
JDialog dlog = jop.createDialog(null, "Backup complete. Ready for encryption.");
dlog.setAlwaysOnTop(true);//make JDialog on top of other windows
dlog.setVisible(true);
The above works on Windows, but note that this behavior may be platform dependent (see docs - you can check if this is supported via the isAlwaysOnTopSupported method)
I have below a javascript function which gets called on click of two separate links provided on a jsp file.
In brief, this functions opens a new popup window. What I want is when I click these two links two new pop up window should open.
But whats happening is this; I click on one link, it opens a new popup window but now I click on second link, it does not open the new popup window instead it is refreshing the old pop-up window (which opened on click of link1) with this link details.
I am not getting how to open two separate pop ups?
function showHelp(orgType) {
var pageLoc = '<%=helpURL%>bin/view/Main/?appSession=<%=request.getSession().getId()% >&securityToken=<%=appUtility.getSecurityToken(session
.getId(), login, custId)%>&appurl=<%=java.net.URLEncoder.encode((new java.net.URL(request.getScheme(),ip,request.getServerPort(), "")).toString() + request.getContextPath(), "ISO-8859-1")%>&custType='+custType+'&custName=<%=hostName%>';
self.open (pageLoc,'ServicePopUp','height=600,width=800,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');
}
You would need to provide a different name for each of the windows to differentiate them from each other:
function showHelp(orgType, windowName) {
...
self.open (pageLoc, windowName,'height=600,width=800,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');
}
See the extra parameter and where it fits into the open function? You'd need to provide 2 different names for the two links. Hope this helps!
We are using webdriver for our functional tests. But our application uses the showModalDialog JS function a lot to open a popup. When we try to test this functionality with webdriver it hangs from the moment the popup is opened.
We tried several things to test this:
Using the workaround explained here. But this seems to be a fix for selenium and not for webdriver. We tried it but it didn't work.
Searching for a good alternative, HtmlUnit opened the modal dialog and could interact with it, but it has it's drawbacks like no visual help to fix certain tests and it stopped execution when it detected a JS error in a JS library we have to use but have no control over.
How can we test this or work around this problem?
From my experiences with various automation tools interaction with "webpage dialog" windows opened from IE using window.showModalDialog() or window.showModelessDialog() is not available.
Since the window is not a "true" window (look at the taskbar, it doesn't even show up) most tools can't "inspect" it and/or interact with it.
However if you do find a tool that will, please advise - there are many people looking for such a beast.
That all said, if you can possibly avoid using either of these 2 proprietary methods you'll have much more luck.
(and yes, for the picky ones, Firefox and Chrome have adopted these kind of dialogs but they don't work quite the same)
None of the answers answer the question. If the driver hangs, then you can't call any methods on it. The question is NOT about finding the pop up, it is about how to stop the driver hanging. The only way I have found is to not use showModalDialog. This can be done by adding the folowing to your test code :
((JavascriptExecutor) driver).executeScript("window.showModalDialog = window.open;");
which calls window.open each time your JavaScript calls window.showModalDialog.
I am using webdriver.SwitchTo().Window() method but my concern is my popup window does not have "Name"
When I use webdriver.WindowHandles it return only one handle, I am using this statement after popup window open.
As I don't have name / handle I cannot switch from parent window to child window.
Any other solution to do the same functionality
First we have to switch to the active element:
driver.switchTo().activeElement();
To check whether we have actually switched to the correct active element:
driver.switchTo().activeElement().getText();
Even if the window doesn't have name u can use
driver.switchTo.defaultcontent();
and perform the operation you want to execute
or else you can get the window handle name using the below command
for (String handle : driver.getWindowHandles()) {
driver.switchTo().window(handle); }
hope this should work for you.
Issue 284 is for WebDriver. It seems that it will be implemented only after Issue 27 will be implemented, so the fix should be in Beta 1 or 2 of WebDriver.
Set<String> beforePopup = driver.getWindowHandles();
Set<String> afterPopup = driver.getWindowHandles();
afterPopup.removeAll(beforePopup);
if(afterPopup.size()==1){
System.out.println(afterPopup.toArray()[0]);
}
driver.switchTo().window((String) afterPopup.toArray()[0]);
What I have been using and it works great for us on with IE and Firefox is to go through popups
and look for a a unique text on the popup you are trying to interact with. Here is the method, let me know if it works for you. Please note the line driver = driver.switchTo().window(windowHandle);
public void switchWindow(String containingText, WebDriver driver) throws Exception {
if ( StringUtils.isEmpty(containingText))
return;
int counter = 1;
int numOfpopups = driver.getWindowHandles().size();
System.out.println("Waiting for popup to load..... # handles:" + numOfpopups);
while ( numOfpopups < 2 && ((counter%10) != 0) ) {
counter++;
try{Thread.sleep(1000);}catch (Exception e) {}
}
System.out.println("Done waiting for..... " + counter + " seconds");
if (driver.getWindowHandles().size() < 2)
throw new BrowserException("Timeout after " + counter + " secs. No popup present. ");
System.out.println("Going through window handles...");
for (String windowHandle : driver.getWindowHandles()) {
driver = driver.switchTo().window(windowHandle);
if ( driver.getPageSource().contains(containingText)
return;
else
continue;
}
throw new Exception("Window containing text '" + containingText + "' not found");
}
To my knowledge, webdriver has no built-in functionality to handle modal windows as of now. Webdriver will hang once you click button which opens modal window. This happens due to JS on parent window halts until child window is closed.
To handle modal windows such as this one, see below for possible workaround written in Java. The main idea is to perform action that opens modal window (click on the button) in new thread.
/**
* Click button to open modal window and switch to it
* #param we webElement handle of a button
*/
public void clickToOpenModal(final WebElement we) {
//Get handles of all opened windows before opening modal window
Set<String> initWindowHandles = getDriverInstance().getWindowHandles();
//Create new thread and click button to open window
Thread thread1 = new Thread() {
#Override
public void run() {
//Click button
click(we);
}
};
thread1.start();
//Wait for window to appear
waitForWindow(initWindowHandles, pauseL);
thread1.interrupt();
thread1 = null;
//Get handles of all opened windows after opening modal window
Iterator<String> it = getDriverInstance().getWindowHandles().iterator();
//Select handle of modal window
String windowHandle = "";
while(it.hasNext()){
windowHandle = it.next();
}
//Switch focus and work on the modal window
getDriverInstance().switchTo().window(windowHandle);
}
The solution by Hugh Foster works, i tried this and succeeded
((JavascriptExecutor) driver).executeScript("window.showModalDialog = window.open;");
You can find the url of modal dialog then open it on another tab, it will work as normal.
In case you want to deal with open modal dialog, you can try to send "tab" key for move around objects and "send keys... enter" for setText or click.
Note: Below is some information why you cannot use selenium webdriver for work with that modal.
Modal pop-up - This is very specific to IE, Microsoft defined it as
When Windows Internet Explorer opens a window from a modal or modeless HTML dialog box by using the showModalDialog method or by using the showModelessDialog method, Internet Explorer uses Component Object Model (COM) to create a new instance of the window. Typically, the window is opened by using the first instance of an existing Internet Explorer process. When Internet Explorer opens the window in a new process, all the memory cookies are no longer available, including the session ID. This process is different from the process that Internet Explorer uses to open a new window by using the open method.
http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx
MSDN blog on Modal dialog
When user select Model popup, parent window is blocked waiting for the return value from the popup window. You will be not able to see the view source of the page, need to close the popup then only the parent window is activated.
I have problem currently for my swing reminder application, which able to minimize to tray on close. My problem here is, I need JOptionPane dialog to pop up on time according to what I set, but problem here is, when I minimize it, the dialog will pop up, but not in the top of windows when other application like explorer, firefox is running, anyone know how to pop up the dialog box on top of windows no matter what application is running?
Create an empty respectively dummy JFrame, set it always on top and use it as the component for the JOptionPane instead of null. So the JOptionPane remains always on top over all other windows of an application. You can also determine where the JOptionPane appears on screen with the location of the dummy JFrame.
JFrame frmOpt; //dummy JFrame
private void question() {
if (frmOpt == null) {
frmOpt = new JFrame();
}
frmOpt.setVisible(true);
frmOpt.setLocation(100, 100);
frmOpt.setAlwaysOnTop(true);
String[] options = {"delete", "hide", "break"};
int response = JOptionPane.showOptionDialog(frmOpt, msg, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, "delete");
if (response == JOptionPane.YES_OPTION) {
removeRow();
}
frmOpt.dispose();
}
Old post, but I was struggling with this.
My problem was more with Javafx allowing the JOptionPane to go behind the current Java window.
Therefore I used the following which does what the original poster asked by putting the JOptionPane in front of all windows; even JAVAFX.
Firstly the old JOptionPane:
JOptionPane.showMessageDialog(null, "Here I am");
Now an JOptionPane that stays in front:
final JDialog dialog = new JDialog();
dialog.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(dialog, "Here I am");
And for fun here is everything in one long line:
JOptionPane.showMessageDialog(
((Supplier<JDialog>) () -> {final JDialog dialog = new JDialog(); dialog.setAlwaysOnTop(true); return dialog;}).get()
, "Here I am");
You can make a static method some where that will return the JDialog for you and then just call it in the JOptionPane to clean up your code a bit.
Are you using one of the canned JOptionPanes? (Like JOptionPane.showCOnfirmDialog(...))
You may want to look at extending JDialog and making your own dialog panel, and then calling myDialog.setAlwaysOnTop(true);
Windows is blocking this operation since XP.
The scenario before was like:
Your a tiping in some text in an editor and not recognize that another dialog is coming to front when you are tipping the text. The coming dialog gets the focus and you are tiping in the new dialog. Maybe you click enter after you are ready and do this in the wrong dialog, which is asking whether you realy want to delet your hard disk ;)
The come to front call in java is only working for java windows.
The possibibilty to notify the user of a new window is to implement a Frame, which will highlighted/flashing in the windows task bar.
Correction the post above..
I have resolve my problem as below:
this.setVisible(true); // show main frame
MyDialog dialog = New MyDialog(this, true); // show my custom dialog
dialog.setVisible(true);
this.setVisible(false);
it works fine for me :)
You might think about using a JFrame instead. It may give you a little more flexibility.
If you are using a JFrame and you want it to popup on top of the other windows use:
myFrame.setVisible(true);
myFrame.setState(Frame.NORMAL);
The setState will show the window to the user if it was in minimized state previously.