Listener not working with Modal Dialog - jdialog

My Intention - Create a frame, add a button. When clicked the button, a Modal Dialog appears with custom buttons and text fields. takes user input from this dialog. close the dialog and pass the value to frame controls.
Question - I successfully achieved this when I created a Modeless dialog, but this does not work with Modal dialog:
when used, modeless dialog, clicking OK button on dialog, passed the value to frame and closed the dialog. But when set the dialog to modal = true, OK button on dialog is not working
code I used:
JButton diabtn = new JButton("Dialog");
diabtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
final JDialog dialog = new JDialog((JFrame)null,"Dia Window",true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setSize(350,200);
JLabel dialbl1 = new JLabel("Enter your name");
JButton diaok = new JButton("OK");
final JTextField diatxt = new JTextField(20);
diaok.setSize(60,60);
dialog.setLayout(new FlowLayout());
dialog.add(dialbl1);
dialog.add(diatxt);
dialog.add(diaok);
dialog.setVisible(true);
// adding listener for button on the dialog
diaok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String tempval = diatxt.getText();
lblDialogValue.setText(tempval);
dialog.dispose();
}
});
}
});

I'm no Java expert, but there is some corroboration for what you are saying: Code after the .setvisible() is only executed after the dialog is closed. See reference.

Related

Unable to move focus using Action class in selenium webdriver

Hello I am working with popup which are made by
So while I click on one button i.e. "click1" it pops up one div window ..
So on this pop up I can play with element by using action class
WebElement element = wd.findElement(By.className("qx-window"));
Actions actions = new Actions(wd);
actions.moveToElement(element).click().perform();
Now from this popup while i click on another button it again pops up another popup and again I tried with action class but unable to set focus on the new pop up
So scenario is main window->popup->popup
can I able to remove focus from first pop up
Hear below selenium code is not working that's why I use action
for (String popup : wd.getWindowHandles())
{
wd.switchTo().window(popup);
}
Try with below flow
//Store main window handle in one variable
String mainWindowHandle = driver.getWindowHandle();
//click something on window to open popup1
Set<String> windowHandles = driver.getWindowHandles(); //It returns Set of available window handles
//from above set get popup1 handle and switch control to popup1
//==switch control to pop-up1
windowHandles.remove(mainWindowHandle);
String popup1Handle=(String)windowHandles.toArray()[0];
driver.switchTo().window(popup1Handle);
//do your operations in popup1
//===== YOUR ACTIONS GOES HERE FOR POPUP1
//click on button in popup1 which will open popup2
//switch the control to popup2
windowHandles = driver.getWindowHandles(); //It returns Set of available window handles, here it returns 3 window handles
windowHandles.remove(mainWindowHandle);
windowHandles.remove(popup1Handle);
String popup2Handle=(String)windowHandles.toArray()[0];
driver.switchTo().window(popup2Handle);
//do your operations in popup2
//===== YOUR ACTIONS GOES HERE FOR POPUP2
driver.close(); // this will close popup2 as control is in popup2
//switch the control to main window again
driver.switchTo().window(mainWindowHandle);

selecting checkboxes in a popup window using selenium webdriver

I have a textbox and a popup window opens on click of this textbox. This popup window contains checkboxes.
I want to click on the above textbox and move the focus to the popup window, select the checkboxes in the popup window and move the focus back to main window.
Image of source code of the popup window is attached in the image tab.
Firefox v33.1
Selenium v2.25
source code
I tried with the below code but it didnt work:
driver.findElement(By.id("FieldView_ctl17_MultiSelect1_InputText")).click();
driver.switchTo().activeElement();
driver.findElements(By.id("checkbox0")).click();
You need to switch on open popup window before finding checkbox as below:-
//First store parent window to switch back
String parentWindow = driver.getWindowHandle();
//Perform the click operation that opens new window
driver.findElement(By.id("FieldView_ctl17_MultiSelect1_InputText")).click();
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
if(!winHandle.equals(parentWindow)) {
driver.switchTo().window(winHandle);
}
}
//Now find checkbox and click
driver.findElements(By.id("checkbox0")).click();
//Now close opened popup window
driver.close();
//Switch back to parent window
driver.switchTo().window(parentWindow);
//Continue with parent window

How to close a popout window using selenium

I'm very new to Selenium and need to be able to close a popout window. I can get it open, but I can't seem to make the code recognize there's a new window. I've tried every code I've found in all of these questions, with parents, and handles and I'm just more confused. My skills are very basic, but any help would be appreciated. The pop up window that opens has a close button, and I have the name for it to click, but I really need the simplest way for the code to recognize the new window before it gets to the close button.
Any help is appreciated!
Going to try to add the code here.
owd.findElement(By.xpath(vath)).click(); //Click ATH button
System.out.println("ATH Report opened");
//#1
//owd.get(vURL2);
//System.out.println("popout is opened");
//#2
//String parentWindowHandler = owd.getWindowHandle(); // Store your parent window
//String subWindowHandler = null;
//#3
//Select handles = (Select) owd.getWindowHandles(); // get all window handles
//Iterator<String> iterator = ((Set<String>) handles).iterator();
//while (iterator.hasNext()){
// subWindowHandler = iterator.next();
//}
//owd.switchTo().window(subWindowHandler); // switch to popup window
// perform operations on popup
//owd.switchTo().window(parentWindowHandler); // switch back to parent window
//#4
//owd.switchTo()).handle().accept();
//#5
//String winHandle = owd.getWindowHandle(); //Get current window handle.
//for(String windowsHandle : owd.getWindowHandles()) {
// owd.switchTo().window(windowsHandle); //Iterate to the new window handle.
/*
Do any action on window or just close it.
*/
// owd.switchTo().window(winHandle); //Switch to original window.
//#6
owd.switchTo().window(vwindow);
owd.findElement(By.xpath(vclose)).click(); //Click Close button
System.out.println("Close button clicked");
you need to switch to active window/popup alert/frame firstly:
driver.SwitchTo().Window(<windowname>)
driver.SwitchTo().Frame("iFrmLinks")
and to close as allways.
if you are talk about alerts:
driver.SwitchTo().Alert();
alert.accept();

How to open dialog or popup when clicking on a cell in Dojo Dgrid

I want to open a dialog box when clicking on a cell.I am using dgrid/editor.
editor({field: "column1",label: "col1",editor: "text",editOn: "click"})
I am getting text box when using the above code.I want a dialog box.Please tell me how to get a dialog box.I am using OndemandGrid with JSONReststore to display the grid.
You don't need use editor to trigger a dialog, use click event on a cell is ok:
var grid = new declare([OnDemandGrid,Keyboard, Selection])({
store: Observable(new Memory({data: []}))
}, yourGridConatiner);
grid.on(".dgrid-content .dgrid-cell:click", function (evt) {
var cell = grid.cell(evt);
var data = cell.row.data;
/* your dialog creation at here, for example like below */
var dlg = new Dialog({
title: "Dialog",
className:"dialogclass",
content: dlgDiv //you need create this div using dojo.create or put-selector
});
dlg.show();
});
If you want show a pointer while mouse over that cell, you can style it at renderCell method with "cursor:pointer"
From the wiki:
editor - The type of component to use for editors in this column; either a string specifying a type of standard HTML input to create, or a Dijit widget constructor to instantiate.
You could provide (to editor) a button that pops up a dialog when clicked, but that would probably mean two clicks to edit a cell: one to focus or enter edit mode or otherwise get the button to appear and one to actually click the button.
You could also not bother with the editor plugin and attach a click event handler to the cell and pop up a dialog from there. You would have to manually save the changes back to your store if you went that route.
If I understand you right - you could try something like this:
function cellFormatter1(value) {
//output html-code to open your popup - ie. using value (of cell)
}
......
{field: "column1",label: "col1", formatter: cellFormatter1 }

pass visible frame reference to settings flyout

In my Windows 8 App, I have a Popup which displays when clicking a link on the charm bar. How do I pass the current applications visible frame to the the popup? I would like to display and do different things based on where they call the charms bar and open the settings.
To create my settings popup i do the following:
void onCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs eventArgs)
{
UICommandInvokedHandler handler = new UICommandInvokedHandler(onSettingsCommand);
SettingsCommand generalCommand = new SettingsCommand("SettingId", "Setting", handler);
eventArgs.Request.ApplicationCommands.Add(generalCommand);
}
void onSettingsCommand(IUICommand command)
{
// Create a SettingsFlyout the same dimenssions as the Popup.
MyApp.Common.LayoutAwarePage mypane = new SettingsFlyout;
}
I think you can pass current frame as DataContext to popup.
var popup = new Popup();
popup.DataContext = this;