How to handle selenium webdriver pop up window

19,812 views
Skip to first unread message

ramshankar behera

unread,
Jun 7, 2012, 3:13:48 AM6/7/12
to Selenium Users
Hi,,,,


I tried
Alert alert = driver.switchTo().alert();
alert.accept()

But i am getting Exception ( if there is any solution then please send
me that code in ramshank...@gmail.com

org.openqa.selenium.NoAlertPresentException: No alert is present
(WARNING: The server did not provide any stacktrace information)

UmaMahesh

unread,
Jun 7, 2012, 3:26:16 AM6/7/12
to seleniu...@googlegroups.com
Hi ramshankar,

if it is alert go like this..


Alert javascriptAlert = driver.switchTo().alert();
javascriptAlert.accept();
javascriptAlert.dismiss();

if it is popup go like this..

windowids = driver.getWindowHandles();
iter= windowids.iterator();
String mainWindowId=iter.next();
String popupWindowId=iter.next();
driver.switchTo().window(popupwindowid);
 
Thanks
Uma Mahesh



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




--
mahesh.......

ranga rao

unread,
Jun 7, 2012, 3:25:22 AM6/7/12
to seleniu...@googlegroups.com
1. "webdeiver.switchTo().window()"
    this method to a window with know name.

2. "webdriver.getwindowHandles()"
    to obtain o list of know window. you may pass the handle to "switchto().window()"

3. if you are using python and webdriver
    def close_all_popups(driver):
        driver.window_handles
        for h in driver.window_handles[1:]:
            driver.switch_to_window(h)
            driver.close()
       driver.switch_to_window(driver.window_handles[0])
 it will close except parent window.

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




--
Thanks and Regards
Ranga
Mob: 91-9986686264

ramshankar behera

unread,
Jun 7, 2012, 5:04:12 AM6/7/12
to Selenium Users
Thank you very much Mahesh for replying me .
But Unfortunately still i am not able to handle this issue.
I tried both of code you sent but exception is coming.

I tried first one that is not able to click that pop up and alert.
I think that is modal dailog window i am not able to click it.

But When i tried 2nd one It closes but it showing Nosuch element
Exception.


MY requirement is to get text body of that modal dailog box and click
OK button of that modal dailog box.But i am not able to do it from
last one week. So please help me.If any clarification let me know
in my number 86955494921.


On Jun 7, 12:26 pm, UmaMahesh <umarao...@gmail.com> wrote:
> Hi ramshankar,
>
> if it is alert go like this..
>
> Alert javascriptAlert = driver.switchTo().alert();
> javascriptAlert.accept();
> javascriptAlert.dismiss();
>
> if it is popup go like this..
>
> windowids = driver.getWindowHandles();
> iter= windowids.iterator();
> String mainWindowId=iter.next();
> String popupWindowId=iter.next();
> driver.switchTo().window(popupwindowid);
>
> Thanks
> Uma Mahesh
>
> On Thu, Jun 7, 2012 at 12:43 PM, ramshankar behera <
>
>
>
> ramshankar.beh...@gmail.com> wrote:
> > Hi,,,,
>
> > I tried
> > Alert alert = driver.switchTo().alert();
> > alert.accept()
>
> > But i am getting Exception ( if there is any solution then please send
> > me that code in ramshankar.beh...@gmail.com

ramshankar behera

unread,
Jun 7, 2012, 5:12:13 AM6/7/12
to Selenium Users
Hii Ranga,

I am not able to handle popwindow/alert in selenium webdriver.

I tried both code below.
Alert javascriptAlert = driver.switchTo().alert();
javascriptAlert.accept();

It is not able to click OK button of Modal dailog window.The execution
is stopping here.Not able to close or click OK.After forcefully
closing it is getting close.


THe 2nd one is

windowids = driver.getWindowHandles();
iter= windowids.iterator();
String mainWindowId=iter.next();
String popupWindowId=iter.next();
driver.switchTo().window(popupwindowid);


Here Iam able to close window but not able to get my requirement.and
here i am getting exception like nosuch element.


My requirement is to gettext of that modal dailog box and click OK
button .

If you wont mind please help me.

On Jun 7, 12:25 pm, ranga rao <crangara...@gmail.com> wrote:
> 1. "webdeiver.switchTo().window()"
>     this method to a window with know name.
>
> 2. "webdriver.getwindowHandles()"
>     to obtain o list of know window. you may pass the handle to
> "switchto().window()"
>
> 3. if you are using python and webdriver
>     def close_all_popups(driver):
>         driver.window_handles
>         for h in driver.window_handles[1:]:
>             driver.switch_to_window(h)
>             driver.close()
>        driver.switch_to_window(driver.window_handles[0])
>  it will close except parent window.
>
> On 7 June 2012 12:43, ramshankar behera <ramshankar.beh...@gmail.com> wrote:
>
>
>
> > Hi,,,,
>
> > I tried
> > Alert alert = driver.switchTo().alert();
> > alert.accept()
>
> > But i am getting Exception ( if there is any solution then please send
> > me that code in ramshankar.beh...@gmail.com
>
> > org.openqa.selenium.NoAlertPresentException: No alert is present
> > (WARNING: The server did not provide any stacktrace information)
>
> > --
> > 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.
>
> --
> Thanks and Regards
> *Ranga*
> Mob: 91-9986686264
Message has been deleted

Madan Singh

unread,
Mar 26, 2013, 5:05:36 AM3/26/13
to seleniu...@googlegroups.com
Hi every one I am using c# as programming language,
I am sucking in one problem, In My page there is popup alert but it
came for some time now can any body help me how Can I handle the
existent or Non Existent of this popup alert.

On Tue, Jan 1, 2013 at 7:26 AM, Anil Patel <anil....@gmail.com> wrote:
> THX....Uma
> (Lifesaver)
> To view this discussion on the web visit
> https://groups.google.com/d/msg/selenium-users/-/ajCDTVeSn5QJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Thanks and Advance

--
M P Singh
9971360313

ash

unread,
Mar 26, 2013, 10:45:51 AM3/26/13
to seleniu...@googlegroups.com
LoL Sucking in one problem ;-).

Apart from the short fun, here's my common function for handling alert in Java that only accepts the alert if it is present. You can convert this same code in C# with small modification.


    public void handleAlert() throws InterruptedException {
        try {
            sleep(500);
            methods.switchTo().alert().accept();
            sleep(500);
        } catch (NoAlertPresentException e) {
            // That's fine.
        }
    }



To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Ramijunnisa Shaik

unread,
Mar 27, 2013, 10:28:13 AM3/27/13
to seleniu...@googlegroups.com
Hi,



String currentWindowHandle =driver.getWindowHandle();

       
         driver.findElement(By.cssSelector("span.ui-menuitem-text")).click();//This is cssSelector of the component whick u click to go to popup window.
         java.util.Set<String> availableWindows =driver.getWindowHandles();
      
               int Windows = 2;//These are the number of windows total.
               if (availableWindows.size()==Windows) {
               String popUpWindowHandle = null;
               for (String windowHandle2 : availableWindows) {
                  if(!availableWindows.equals(currentWindowHandle))
                     popUpWindowHandle= windowHandle2;
                           driver.switchTo().window(popUpWindowHandle); }
               }




Try this Code.

Thanks&Regards,
Ramija.

imam

unread,
Mar 30, 2013, 8:27:20 AM3/30/13
to seleniu...@googlegroups.com

Hi Selenium Users,

i am using Backed selenium webdriver in eclipse,

here, i am unable to move to main page after selecting some option in popup..
my scenario looks like this...

- click on a button which opens a popup
- select a option in opened popup
- (here after selecting that popup automatically closed, that is the actual functionality)
- click on submit button in main page.
For the above scenario, this is my script..
        // clicks a button, which opens a popup
        driver.findElement(By.id("btn_expense_type")).click();
       // popup selection process
        String str3[]= selenium.getAllWindowNames();
        System.out.println("window names are:"+str3);
        selenium.selectWindow(str3[1]);
        //click on a link in pop up
        selenium.click("link=Mobile recharge");
        //click on save button in main page
        driver.findElement(By.xpath("//input[@id='SAVE_FOOTER']")).click();


       (please find attachment for snapshot)

       All suggestions are highly Appreciable.
POPUP_Handling.PNG

SantoshSarma

unread,
Apr 3, 2013, 5:12:50 AM4/3/13
to seleniu...@googlegroups.com
@Imam : 

to selecy main window again you should use below line

selenium.selectWindow("");


You can find logic in WebDriver for switching between windows here.


Regards,

Ripon Al Wasim

unread,
Apr 15, 2013, 12:36:48 AM4/15/13
to seleniu...@googlegroups.com
hi,
Your error/exception shows that, no alert is present. Can you pls check whether alert is present or not.

br,
Ripon


Ramesh Yatam

unread,
Apr 15, 2013, 12:56:25 AM4/15/13
to seleniu...@googlegroups.com
Hi Ripon,
 
unable unable to run the script, because iam getting red line(error message) on alert() method, iam right click on that then it is saying to rename that, i did that but still that error is not going out.
 
Alert alert1= driver.switchof().alert()
 
Iam getting error at bold text


--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/KvHfsWg2F5E/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Ripon Al Wasim

unread,
Apr 15, 2013, 1:50:36 AM4/15/13
to seleniu...@googlegroups.com
hi,
Can you please check whether it is alert or window?

br,
Ripon


To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

NagarjunReddy K

unread,
Apr 15, 2013, 2:03:51 AM4/15/13
to seleniu...@googlegroups.com
Hi,

Plz rename the swithof() to switchTo() and then try it out.

Alert alert1= driver.switchTo().alert();
--
Thanks & Regards
NagiReddy. K
Mob:+91-9966585691

Ripon Al Wasim

unread,
Apr 15, 2013, 2:07:52 AM4/15/13
to seleniu...@googlegroups.com
yes, this is not switchOf() . it is switchTo()

Dave

unread,
Jul 23, 2013, 8:29:59 PM7/23/13
to seleniu...@googlegroups.com
I am using Python, and tried example #3. Does not work. Does anyone have a viable solution to Chrome Driver?
Reply all
Reply to author
Forward
0 new messages