Switching from parent window to modal dialog

2,963 views
Skip to first unread message

mukesh rawat

unread,
May 9, 2012, 8:22:58 AM5/9/12
to webdriver
Hi,

In my application "modal frame dialog window" opens after clicking on
radio button. I am using getWindowHandles() function but it doesn't
gives the dialog window handle. It only gives the handle of parent
window.

I am using code:-

String currentWindowHandle=objDriver.getWindowHandle();
objWebElement = objDriver.findElement(By.id(strTarget1));
objWebElement.click();
String htmlModalWindowHandle= null ;
Set<String> handles = objDriver.getWindowHandles();
for(String windowHandle:handles)
{
System.out.println(windowHandle);
if (!windowHandle.equals(currentWindowHandle)){
htmlModalWindowHandle=windowHandle;
System.out.println(htmlModalWindowHandle);
}
}
objDriver.switchTo().window(htmlModalWindowHandle);

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
It shows "java.lang.NullPointerException" error
As getWindowHandles() only give the handle of parent window not for
modal dialog.


Thanks
Mukesh
mraw...@gmail.com

Danny Guerrier

unread,
May 9, 2012, 8:37:56 AM5/9/12
to webd...@googlegroups.com
It sounds like the application is not opening another browser window
and is instead opening a modal. If that is the case then this is the
correct behavior and you should instead use findElement to interact
with the modal.

A screenshot and HTML would be helpful to see what is going on.
> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

mukesh rawat

unread,
May 9, 2012, 11:15:59 AM5/9/12
to webd...@googlegroups.com
Hi danny,

I am attaching the screenshot of my app where i stuck.
In homepage.bmp is my home page of app, where i have to select radio button(name=Resource) under "Assigned By" and after selecting modaldialog opens.
In modaldialog , i have to select a checkbox and then click on select button.
After select button click modaldialog closes and return to parent window( which is homeScreenAfterModalDialog) where selected chekbox value is displayed.


Note: This app only for IE
Please help ASAP,
Regards,
Mukesh

> To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.
homepage.png
HomeScreenAfterModalDlg.png
modaldialog.png

Jim Evans

unread,
May 9, 2012, 12:36:35 PM5/9/12
to webd...@googlegroups.com
Two questions: First, what version of the Selenium library are you using? There were changes in the last few versions in this area, and if you're using a sufficiently older version, you might have problems. Second, what happens if you delay your call to getWindowHandles()? Since mouse clicks are asynchronous, you'll need to wait for a bit to make sure the popup window appears. For now, try a simple Thread.sleep(). If that solves the problem, you'll want to refactor the code to use some sort of wait routine (like a WebDriverWait).

--Jim

sai kiran

unread,
May 9, 2012, 12:36:27 PM5/9/12
to webd...@googlegroups.com
Hi Mukesh,

Second screenshot looks like you have dialog window (Assigned by Resources)  and third screenshot is different from second which is opened in window. if it is window that you want to handle the above should work

Thanks

mukesh rawat

unread,
May 10, 2012, 2:34:16 AM5/10/12
to webd...@googlegroups.com
Hi,
 Iam using selenium 2.20 libraries. And also use wait before getWindowHandles(), but it will always retuen me only parent window handle.
My code is below:

          String currentWindowHandle=objDriver.getWindowHandle();
        objWebElement = objDriver.findElement(By.id("strTarget1"));
             objWebElement.click();
        
              Thread.sleep(30000); // surrounds in try catch  // Iam also us implicit wait

Manoj

unread,
Nov 2, 2012, 8:24:00 AM11/2/12
to webd...@googlegroups.com


See this it will help u out...https://groups.google.com/forum/?fromgroups=#!searchin/webdriver/manoj$20hans$20modal/webdriver/4n68vqEl30Q/5WGT-W-yDSQJ


--Manoj Hans

On Thursday, November 1, 2012 2:26:17 AM UTC+5:30, rakesh wrote:
Hi Mukesh,
Where you able to figure this out? I am also not able to find and switch to 2nd window (modal dialog).

Thanks,
Rakesh
Reply all
Reply to author
Forward
0 new messages