driver.switchTo().window("windowName"); not working

1,040 views
Skip to first unread message

ravindra.k

unread,
Jan 18, 2012, 12:54:24 AM1/18/12
to seleniu...@googlegroups.com
Hi All,

Have a look at the code below :

for (String handle : driver.getWindowHandles()) {             
driver.switchTo().window(handle);
}


Using the above code, I am able to switch to next browser window and able to do some operations.

But the following code: 

//String fbpath ="Log In | Facebook";   // Using Title of FB login window
String fbpath ="_blank";  // Using Target of FB login window
 
driver.switchTo().window(fbpath)  : is not at all working

>fbpath is a String variable for which we can use either Title or Target of the FB login window, according to Selenium docs : http://seleniumhq.org/docs/03_webdriver.html
Ref : Moving Between Windows and Frames¶

But this is not working. I am not sure if I am doing something wrong. Any help appreciated. 

--
Regards,
Ravindra K

saju thomas

unread,
Jan 18, 2012, 2:20:39 AM1/18/12
to Selenium Users
Use either the window name or window handle . The target of fb window
seems wrong . Also is the window of FB a resulting action of the web
driver instance.


On Jan 18, 10:54 am, "ravindra.k" <ravi....@gmail.com> wrote:
> Hi All,
>
> Have a look at the code below :
>
> for (String handle : driver.getWindowHandles()) {
> driver.switchTo().window(handle);
>
> }
>
> Using the above code, I am able to switch to next browser window and able
> to do some operations.
>
> But the following code:
>
> //String fbpath ="Log In | Facebook";   // Using Title of FB login window
> String fbpath ="_blank";  // Using Target of FB login window
>
> *driver.switchTo().window(fbpath)  : is not at all working*

ravindra.k

unread,
Jan 18, 2012, 7:20:00 AM1/18/12
to seleniu...@googlegroups.com
Hi Saju,

Thanks for the reply. If I use window handle, I am able to switch between the browser windows.

If I use  driver.switchTo().window(fbpath) , its not working.

If you open Facebook login window and see the source code, the target is "_blank",  if this is used as fbpath, its not able to find the FB login window.

Error displayed will be : Not able to find the window. Hope I am clear now.


Thanks
Ravindra

--
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.




--
Regards,
Ravindra K

Luke Inman-Semerau

unread,
Jan 18, 2012, 7:55:26 AM1/18/12
to seleniu...@googlegroups.com
Window Name is not "_blank" in this case. I'm not certain exactly what each browser does, but I'd guess it's "". Which would not make it distinguishable from the other window(s).

The window name that is being referred to is the one that is used by JavaScript window.open:

open (URL, windowName[, windowFeatures])

For new windows opened by "target" you'll have to use the window handles. 

-Luke

ravindra.k

unread,
Jan 18, 2012, 9:13:44 AM1/18/12
to seleniu...@googlegroups.com
Hi Luke,

Thanks for the reply. It makes sense. Using window handlers, I am successfully able to switch between the 2 browsers windows.


Thanks
Ravindra
Reply all
Reply to author
Forward
0 new messages