How to focus on a POP up Window.

1,653 views
Skip to first unread message

sam

unread,
Jul 25, 2011, 7:29:45 AM7/25/11
to webdriver
Hi Guys ,

I have a problem with switching to the pop up window ..
i need to verify the text field and then need fill the form n
submit ..

which command should i use to get the pop window in focus ??

Harish Kumar

unread,
Jul 25, 2011, 7:37:29 AM7/25/11
to webd...@googlegroups.com

try to use:
selenium.windowFocus(); 


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




--
Thank You

HARISH KUMAR

Harish Kumar

unread,
Jul 25, 2011, 7:38:02 AM7/25/11
to webd...@googlegroups.com

sam

unread,
Jul 25, 2011, 8:04:19 AM7/25/11
to webdriver
Its focusing on the parent window harish ...



On Jul 25, 4:38 pm, Harish Kumar <harishbansa...@gmail.com> wrote:
> http://opensource-soa.blogspot.com/2009/10/how-to-capture-pop-up-wind...
>
> On Mon, Jul 25, 2011 at 5:07 PM, Harish Kumar <harishbansa...@gmail.com>wrote:
>
>
>
>
>
> > try to use:
> > selenium.windowFocus();
>
> > On Mon, Jul 25, 2011 at 4:59 PM, sam <hotdude...@gmail.com> wrote:
>
> >> Hi Guys ,
>
> >> I have a problem with switching to the pop up window ..
> >> i need to verify the text field and then need fill the form n
> >> submit ..
>
> >> which command should i use to get the pop window in focus ??
>
> >> --
> >> 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.
>
> > --
> > Thank You
>
> > *HARISH KUMAR*
>
> --
> Thank You
>
> *HARISH KUMAR*

sam

unread,
Jul 26, 2011, 4:37:09 AM7/26/11
to webdriver

Hi Guys,

I used driver.getWindowHandles();

i get the window name as :[{6b092905-f006-4d16-95da-e305ebc4ef9c},
{9346916f-75b2-49b6-8a15-1c58d7ebcadd}]


everytime the window name is been changing .. wat should i do to focus
on the pop up window ??

sam

unread,
Jul 26, 2011, 5:22:20 AM7/26/11
to webdriver

Set<String> afterHandles = fatwire.getWindowHandles();

afterHandles.removeAll(beforeHandles);


System.out.println("window name " + afterHandles );
//fatwire.switchTo().window("9c190f96-e1ef-4f23-a176-c29075f142fb");
fatwire.switchTo().window(afterHandles.iterator().next());


i tried this method.. n still the window is not getting focused.

Danny Guerrier

unread,
Jul 26, 2011, 7:43:41 AM7/26/11
to webd...@googlegroups.com
You don't need to get the window name. Just get the window handles
before doing the action that opens the window and again after.
Now you just have focus on the handle that is not in the before set of handles.

sam

unread,
Jul 27, 2011, 1:02:52 AM7/27/11
to webdriver
Hi Danny ,

Can u provide me a snippet of how to do that ???


On Jul 26, 4:43 pm, Danny Guerrier <dguerr...@gmail.com> wrote:
> You don't need to get the window name. Just get the window handles
> before doing the action that opens the window and again after.
> Now you just have focus on the handle that is not in the before set of handles.
>

Danny Guerrier

unread,
Jul 27, 2011, 9:46:01 AM7/27/11
to webd...@googlegroups.com

 Something like this should work.  BTW I used to work at fatwire; small world.  

        

       //Get current windows

          final Set<String> beforeHandles = driver.getWindowHandles();

          element.click(); //click action that cause new window to open 

//wait for the new window to open

new WebDriverWait(driver, 30){ 

   

    }.until(new ExpectedCondition<Boolean>(){

   

        public Boolean apply(WebDriver driver) { 

       

return (driver.getWindowHandles().size() > beforeHandles.size()) ? true : false;

                

    }});

//Get after handles

Set<String> afterHandles = driver.getWindowHandles();

//remove all before handles from after.  Leaves you with new window handle

afterHandles.removeAll(beforeHandles);

 

//Switch to the new window

String newWindowHandle = afterHandles.iterator().next();

driver.switchTo().window(newWindowHandle);

sam

unread,
Jul 27, 2011, 10:08:35 AM7/27/11
to webdriver
Hey Danny , this works fine .. awesome .. thanks a ton ..

Even i'm working on FATWIRE .... i was trying to make this code work
on fatwire ..

Can u please explain wat exactly is this part doing ..

new WebDriverWait(driver, 30){

}.until(new ExpectedCondition<Boolean>(){

public Boolean apply(WebDriver driver) {

return (driver.getWindowHandles().size() > beforeHandles.size()) ?
true :
false;

}});

A part from the above code .. i was working on the remaining steps ..
but i had no luck .. after the insertion of above code.. it worked ..
thanks a ton ..

Looking forward for ur reply ...



On Jul 27, 6:46 pm, Danny Guerrier <dguerr...@gmail.com> wrote:
>  Something like this should work.  BTW I used to work at fatwire; small
> world.
>
>        //Get current windows
>
>           final Set<String> beforeHandles = driver.getWindowHandles();
>
>           element.click(); //click action that cause new window to open
>
>   //wait for the new window to open
>
>  new WebDriverWait(driver, 30){
>
>     }.until(new ExpectedCondition<Boolean>(){
>
>         public Boolean apply(WebDriver driver) {
>
>  return (driver.getWindowHandles().size() > beforeHandles.size()) ? true :
> false;
>
>     }});
>
>   //Get after handles
>
>  Set<String> afterHandles = driver.getWindowHandles();
>
>    //remove all before handles from after.  Leaves you with new window
> handle
>
>  afterHandles.removeAll(beforeHandles);
>
>  //Switch to the new window
>
>  String newWindowHandle = afterHandles.iterator().next();
>
>  driver.switchTo().window(newWindowHandle);
>

Danny Guerrier

unread,
Jul 27, 2011, 10:27:10 AM7/27/11
to webd...@googlegroups.com
This is the selenium 2 way of waiting for expected events.
In this case I'm waiting for the amount of windows that are open after the click that opens to the new window to be greater than what it was prior to clicking.
This way I'm sure that the second window is open before I try to switch to it.


So this says if new window count is greater than the old window count within 30 seconds then return true and proceed.

new WebDriverWait(driver, 30){

   }.until(new ExpectedCondition<Boolean>(){

       public Boolean apply(WebDriver driver) {

 return (driver.getWindowHandles().size() > beforeHandles.size()) ?
true :
false;

   }});

sam

unread,
Jul 27, 2011, 10:29:46 AM7/27/11
to webdriver
Thanks for the quick response Danny ..

Its been very kind of you .. Now i understand the concept .. thanks a
lot ..


On Jul 27, 7:27 pm, Danny Guerrier <dguerr...@gmail.com> wrote:
> This is the selenium 2 way of waiting for expected events.
> In this case I'm waiting for the amount of windows that are open after the
> click that opens to the new window to be greater than what it was prior to
> clicking.
> This way I'm sure that the second window is open before I try to switch to
> it.
>
> So this says if new window count is greater than the old window count within
> 30 seconds then return true and proceed.
>
> new WebDriverWait(driver, 30){
>
>    }.until(new ExpectedCondition<Boolean>(){
>
>        public Boolean apply(WebDriver driver) {
>
>  return (driver.getWindowHandles().size() > beforeHandles.size()) ?
> true :
> false;
>
>    }});
>
Reply all
Reply to author
Forward
0 new messages