Select new open window

454 views
Skip to first unread message

Pooja

unread,
Mar 18, 2010, 6:41:03 AM3/18/10
to Selenium Users
Hi all,

i am facing a very common problem. but unfortunatly no solution worked
for me.
i am using selenium server 1.0.3.
in my application, i click a button and it opens a new window with
results.

new window doesnot contain window id or window name but only title.
and i am not able to focus this window as selenium does not recognise
it. and gives exceptions while trying to find out new window's
elements.

selenium.Open("http://www.abc.com/"); //main
window
selenium.Click("//div[@id='mainImage']/a/img"); //click on image on
main window
// new window opens
up
selenium.SelectWindow("title=New
Window"); //select newly opened window.
selenium.Click("//img[@alt='Get Flash
Plugin']"); //click image on newly opened
window.

nw selenium gives exception while searching for img to click bcoz it
does not find .
thanks in advance.

RITESH MAHAJAN

unread,
Mar 18, 2010, 8:16:57 AM3/18/10
to seleniu...@googlegroups.com
Hi,

Add selenium.windowFocus(); after selenium.selectWindow command.

Thanks
Ritesh


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--
Ritesh Mahajan

darrell

unread,
Mar 18, 2010, 5:35:11 PM3/18/10
to Selenium Users
Two things pop to mind for me. The first is there is no wait for the
new window to load. Have a look at
http://i-am-geek.blogspot.com/2010/02/how-to-handling-timing-in-selenium.html.
Specifically, selenium.waitForPopUp().

Second, are you sure that the title, as Selenium sees it, is "New
Window"? There is a selenium.getAllWindowTitles() method. Once you
have the waitForPopUp in place, call the getAllWindowTitles method and
see what titles Selenium can see. You might also want to call the
getAllWindowNames and getAllWindowIds methods as well, just to confirm
there is no id or name for the new window.

Darrell

Pooja

unread,
Mar 19, 2010, 1:39:12 AM3/19/10
to Selenium Users
thanks for reply.

i tried using
selenium.WaitForPageToLoad("60000"); it gives exception after time
out.
and i tried to find out title, id and name of new window using
selenium.GetAllWindowTitles(); selenium.GetAllWindowIds();
selenium.GetAllWindowNames();
but all three only recognise the main window opened by selenium.
this is my code
try
{
selenium.SelectWindow("null");
selenium.Type("NAME", "davis");
selenium.Click("NAME_SRCH_BTN"); //button to
click ... it opens new window with title "Fund List".
//Thread.Sleep(50000);
selenium.WaitForPageToLoad("60000");
//selenium.WaitForPopUp("","10000"); // i have no
window id to supply here
string[] titles = selenium.GetAllWindowTitles(); //show
only main window title "Fund Search"
string[] ids = selenium.GetAllWindowIds(); // show
only main window id as "undefined"
string[] names = selenium.GetAllWindowNames(); // show only main
window as "selenium_main_app_window"
selenium.SelectWindow("title=Fund List"); // gives
exception that could not find window with title Fund List.. although
the window exists there.
selenium.WindowFocus();
selenium.Click("//img[@alt='Download']");
}
catch(Exception e)
{
Log_info("Error:" + e );
}
i m using c# and selenium-dotnet-client-driver-1.0.1.

On Mar 19, 2:35 am, darrell <darrell.grain...@gmail.com> wrote:
> Two things pop to mind for me. The first is there is no wait for the

> new window to load. Have a look athttp://i-am-geek.blogspot.com/2010/02/how-to-handling-timing-in-selen....

> > thanks in advance.- Hide quoted text -
>
> - Show quoted text -

darrell

unread,
Mar 19, 2010, 10:35:34 PM3/19/10
to Selenium Users
My blog has moved. If you are looking for the article noted below it
is now located at http://darrellgrainger.blogspot.com/2010/02/how-to-handling-timing-in-selenium.html

On Mar 18, 5:35 pm, darrell <darrell.grain...@gmail.com> wrote:
> Two things pop to mind for me. The first is there is no wait for the

> new window to load. Have a look athttp://i-am-geek.blogspot.com/2010/02/how-to-handling-timing-in-selen....

darrell

unread,
Mar 19, 2010, 11:16:13 PM3/19/10
to Selenium Users
I don't know C# so I'll write this as pseudo code, try this:

try {
selenium.SelectWindow("null");
selenium.Type("NAME", davis");
selenium.Click("NAME_SRCH_BTN");

// give it 20 seconds to open the new window
// this is important to this exploration
Thread.Sleep(20000);
string[] titles = selenium.GetAllWindowTitles();
string[] names = selenium.GetAllWindowNames();
string[] Ids = selenium.GetAllWindowIds();
// print the contents of the arrays here


} catch(Exception e) {
Log_info("Error: " + e);
}

You don't want to wait for the page/popup/frame/condition then get the
titles, names and ids. You want to sleep long enough you are positive
the new window is present then get all the titles, names and ids. If
you find there is a name, title or id to look for you can change the
code to:

try {
selenium.SelectWindow("null");
selenium.Type("NAME", davis");
selenium.Click("NAME_SRCH_BTN");

string locator = "????";
selenium.WaitForPopUp(locator);


} catch(Exception e) {
Log_info("Error: " + e);
}

where ???? is the name=, title= or id= locator. If this does not work
you'll either have to ask the developers to put a title, id or name to
the window or get creative. I had one instance where I just knew the
new open window was the window I wanted. So I just switched to the
first child of the current window. I believe using
selenium.SelectPopUp(null); did the trick.

Darrell

Pooja

unread,
Mar 24, 2010, 7:24:36 AM3/24/10
to Selenium Users

Hi,
sorry for late reply.
the application i was working on was down.

@darrell
i tried the solutions. but none of them worked for me.
used selenium.selectpopup(null) but is also did nt recognise the child
window.
please suggest some other solution.
thanks in advance.


On Mar 20, 8:16 am, darrell <darrell.grain...@gmail.com> wrote:
> I don't know C# so I'll write this as pseudo code, try this:
>
>     try {
>         selenium.SelectWindow("null");
>         selenium.Type("NAME", davis");
>         selenium.Click("NAME_SRCH_BTN");
>         // give it 20 seconds toopenthenewwindow
>         // this is important to this exploration
>         Thread.Sleep(20000);
>         string[] titles = selenium.GetAllWindowTitles();
>         string[] names = selenium.GetAllWindowNames();
>         string[] Ids = selenium.GetAllWindowIds();
>         // print the contents of the arrays here
>     } catch(Exception e) {
>         Log_info("Error: " + e);
>     }
>
> You don't want to wait for the page/popup/frame/condition then get the
> titles, names and ids. You want to sleep long enough you are positive

> thenewwindowis present then get all the titles, names and ids. If


> you find there is a name, title or id to look for you can change the
> code to:
>
>     try {
>         selenium.SelectWindow("null");
>         selenium.Type("NAME", davis");
>         selenium.Click("NAME_SRCH_BTN");
>         string locator = "????";
>         selenium.WaitForPopUp(locator);
>     } catch(Exception e) {
>         Log_info("Error: " + e);
>     }
>
> where ???? is the name=, title= or id= locator. If this does not work
> you'll either have to ask the developers to put a title, id or name to

> thewindowor get creative. I had one instance where I just knew thenewopenwindowwas thewindowI wanted. So I just switched to the
> first child of the currentwindow. I believe using


> selenium.SelectPopUp(null); did the trick.
>
> Darrell
>
> On Mar 19, 1:39 am, Pooja <poojajinda...@gmail.com> wrote:
>
>
>
> > thanks for reply.
>
> > i tried using
> > selenium.WaitForPageToLoad("60000"); it gives exception after time
> > out.
> > and i tried to find out title, id and name ofnewwindowusing
> > selenium.GetAllWindowTitles(); selenium.GetAllWindowIds();
> > selenium.GetAllWindowNames();

> > but all three only recognise the mainwindowopened by selenium.


> > this is my code
> > try
> > {
> >   selenium.SelectWindow("null");
> >   selenium.Type("NAME", "davis");
> >   selenium.Click("NAME_SRCH_BTN");                    //button to

> > click ... it opensnewwindowwith title "Fund List".


> >   //Thread.Sleep(50000);
> >   selenium.WaitForPageToLoad("60000");
> >   //selenium.WaitForPopUp("","10000");                    // i have no

> >windowid to supply here


> >   string[]  titles =  selenium.GetAllWindowTitles();        //show

> > only mainwindowtitle "Fund Search"


> >   string[] ids = selenium.GetAllWindowIds();                // show

> > only mainwindowid as "undefined"


> >   string[] names = selenium.GetAllWindowNames();    // show only main

> >windowas "selenium_main_app_window"


> >   selenium.SelectWindow("title=Fund List");                // gives
> > exception that could not findwindowwith title Fund List.. although

> > thewindowexists there.


> >   selenium.WindowFocus();
> >   selenium.Click("//img[@alt='Download']");}
>
> > catch(Exception e)
> > {
> >   Log_info("Error:" + e );}
>
> > i m using c# and selenium-dotnet-client-driver-1.0.1.
>
> > On Mar 19, 2:35 am, darrell <darrell.grain...@gmail.com> wrote:
>
> > > Two things pop to mind for me. The first is there is no wait for the

> > >newwindowto load. Have a look athttp://i-am-geek.blogspot.com/2010/02/how-to-handling-timing-in-selen....


> > > Specifically, selenium.waitForPopUp().
>
> > > Second, are you sure that the title, as Selenium sees it, is "New
> > >Window"? There is a selenium.getAllWindowTitles() method. Once you
> > > have the waitForPopUp in place, call the getAllWindowTitles method and
> > > see what titles Selenium can see. You might also want to call the
> > > getAllWindowNames and getAllWindowIds methods as well, just to confirm
> > > there is no id or  name for thenewwindow.
>
> > > Darrell
>
> > > On Mar 18, 6:41 am, Pooja <poojajinda...@gmail.com> wrote:
>
> > > > Hi all,
>
> > > > i am facing a very common problem. but unfortunatly no solution worked
> > > > for me.
> > > > i am using selenium server 1.0.3.
> > > > in my application, i click a button and it opens anewwindowwith
> > > > results.
>

> > > >newwindowdoesnot containwindowid orwindowname but only title.
> > > > and i am not able to focus thiswindowas selenium does not recognise
> > > > it. and gives exceptions while trying to find outnewwindow's


> > > > elements.
>
> > > > selenium.Open("http://www.abc.com/");                     //main
> > > >window
> > > > selenium.Click("//div[@id='mainImage']/a/img");               //click on image on
> > > > mainwindow
> > > > //newwindowopens
> > > > up
> > > > selenium.SelectWindow("title=New
> > > >Window");                             //select newly openedwindow.
> > > > selenium.Click("//img[@alt='Get Flash
> > > > Plugin']");                         //click image on newly opened
> > > >window.
>
> > > > nw selenium gives exception while searching for img to click bcoz it
> > > > does not find .
> > > > thanks in advance.- Hide quoted text -
>

> > > - Show quoted text -- Hide quoted text -

vinod kumar

unread,
Mar 24, 2010, 11:04:01 AM3/24/10
to seleniu...@googlegroups.com
Did you got the solution?

i assume when u click on Click("//div[@id='mainImage']/a/img");link is it opening a new window with different domain(other than abc.com) or new window with same domain.

As of my knowledge, solutions assisted by darrell should work for pop-up window/window/frames

Thanks
Vinod

Pooja

unread,
Mar 25, 2010, 6:16:24 AM3/25/10
to Selenium Users
No. i didnt get any solution.
in my application (which is converted from java to c#.Net)
In HTML code on submit button click , form action is
"FundSearch.do" (which as i knw is a java servlet)
and open results in a new window.
now i need to perform operations on the new window.
but i am not able to select/focus that window using selenium or any
other means.

Thanks,
Pooja

> > selenium-user...@googlegroups.com<selenium-users%2Bunsubscribe@go­oglegroups.com>


> > .
> > For more options, visit this group at

> >http://groups.google.com/group/selenium-users?hl=en.- Hide quoted text -

sasidhar karri

unread,
Mar 25, 2010, 6:55:35 AM3/25/10
to seleniu...@googlegroups.com
Hi,

Give a try with seleniu.selectwindow(selenium.getallwindownames[](1))

--
Regards,
Sasi

Reply all
Reply to author
Forward
0 new messages