Need help: How to deal with 'Modal popup' and 'Ajax window popup' windows.

6,119 views
Skip to first unread message

rajesh

unread,
Sep 15, 2012, 11:44:37 AM9/15/12
to seleniu...@googlegroups.com
Hi,

I am using selenium webdriver to automate a web application.
In the application thee are some 'Modal pop up' windows and some are 'Ajax pop up' windows.
I have tried with:
driver.switchto().window()  and
Alert alert = driver.switchto().alert()
But none of them are working.
Please suggest a solution for this.


Regards,
Rajesh
Email: raj2...@gmail.com  

akki

unread,
Sep 15, 2012, 12:38:53 PM9/15/12
to seleniu...@googlegroups.com
AJAX modal pop ups are not handled in the same way as browser alerts. You can easily find locators for the web elements on AJAX modals and perform the desired action on them like you do on any other web element.

 P.S: I am working on a site with a lots of these AJAX modals.

Lolz ha ha ha

unread,
Sep 16, 2012, 3:39:53 AM9/16/12
to seleniu...@googlegroups.com
Hi akki,

Can you plz provide a sample code, as am also facing the same problem what Rajesh is facing.

Regards
Nitin Rajpal

akki

unread,
Sep 16, 2012, 8:52:39 PM9/16/12
to seleniu...@googlegroups.com
Example Test Case: Log into your gmail account and select one/more of the emails and click on the report spam icon. It will make an alert modal pop up. Now use firebug/firepath to find locators of the elements on the modal. Lets say you want to click on 'Report Spam' button. You can do that just by writing

driver.findElement(By.xpath("html/body/div[8]/div[3]/button[1]")).click()

The point which I am trying to make is AJAX modal is just a web element. So you can perform all those actions which you can perform on a normal web element.

rajesh

unread,
Sep 17, 2012, 11:09:20 AM9/17/12
to seleniu...@googlegroups.com
Locating the buttons or fields in a pop up window using xpath or id is not working, as the button is in a new window.
And the control is still in the main window and not in the pop up window. I am facing issue with handling a pop up window inside a pop up window.
As i am not able to set the control in the 2nd pop up window, find element is failing.




Regards,
Rajesh
Email: raj2...@gmail.com  

--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/28DyvI5tDw8J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



Nitin Rajpal

unread,
Sep 17, 2012, 12:25:09 PM9/17/12
to seleniu...@googlegroups.com
Hi,

Please provide the solution of the below code:
WebDriver driver = new FirefoxDriver();
Thread.sleep(3000l);
driver.findElement(By.xpath(".//*[@id='docs_MiniGlass_0']/a[1]/span")).click();

I want to have control in the popup.

Early response will be highly appreciable.

Thank You
Nitin Rajpal

Peter Gale

unread,
Sep 17, 2012, 12:44:28 PM9/17/12
to Selenium Users
Nitin,

PLease do no hijack threads.

If you have a new issue you want help with, start a new thread.

Peter


Date: Mon, 17 Sep 2012 09:25:09 -0700
From: nitin...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: Need help: How to deal with 'Modal popup' and 'Ajax window popup' windows.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/DqnzBvlH0ukJ.

Nitin Rajpal

unread,
Sep 17, 2012, 12:48:59 PM9/17/12
to seleniu...@googlegroups.com
Hi Peter,

Hope you are doing good. About hijacking, its not like that. I think the topic is similar to what I have problem. If you have the solution , please let me know. Its just we are spreading knowledge.

Regards
Nitin Rajpal

Peter Gale

unread,
Sep 17, 2012, 12:50:52 PM9/17/12
to Selenium Users
It might be similar, but it's obviously not the SAME issue. Start a new thread.


Date: Mon, 17 Sep 2012 09:48:59 -0700
From: nitin...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: Need help: How to deal with 'Modal popup' and 'Ajax window popup' windows.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/45EHykZfzl4J.

rajesh

unread,
Sep 17, 2012, 12:56:17 PM9/17/12
to seleniu...@googlegroups.com
Hi All,

I am using selenium webdriver to automate a web application. In the application thee are some 'Modal pop up' windows and some are 'Ajax pop up' windows inside a pop up window. I switched the control to first pop up window using : driver.switchto().window("popup".
But i am not able to switch the control to 2nd pop up window which opens after clicking on a button in 1st pop up window.
Please suggest a solution for this.


Regards,
Rajesh
Email: raj2...@gmail.com  

Peter Gale

unread,
Sep 17, 2012, 12:59:24 PM9/17/12
to Selenium Users
Rajesh

Please supply more concrete details of your problem ... screenshots, source html code of the application you are testing, and the test scripts you have tried.

Peter


Date: Mon, 17 Sep 2012 22:26:17 +0530

Subject: Re: [selenium-users] Re: Need help: How to deal with 'Modal popup' and 'Ajax window popup' windows.

rajesh

unread,
Sep 17, 2012, 1:14:56 PM9/17/12
to seleniu...@googlegroups.com
I have tried with :driver.switchTo().window("popup") to switch the control to first pop up window.
I tried with the window title in place of 'popup'. But nothing worked. So i just tried with 'popup' and it worked.
But now clicking on a button i am getting one more window, which has a combo box and two buttons to update and cancel the selection.
Below i have provided the html part of 2nd pop up window. I want to switch the control to this second window, change the combo box value, click on update button. And switch back the control to first pop up window.
<head><title>
	Change WorkType
</title>
    <base target="_self" />
    <meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />  
    
    <script type="text/javascript" language="javascript">
        function RefreshParentPage(msg) {

            alert(msg);

            if (parent.dialogArguments)
                parent.dialogArguments.ReloadTranscriptEditor();
            else if (window.opener)
                window.opener.ReloadTranscriptEditor();

            self.close();
        }

    </script>


Regards,
Rajesh
Email: raj2...@gmail.com 

Peter Gale

unread,
Sep 17, 2012, 1:20:58 PM9/17/12
to Selenium Users
Looks like you have dealt with the "alert(msg);" popup.
You could be gettign eother of these two windows/dialogs appearing:
   parent.dialogArguments.ReloadTranscriptEditor();
window.opener.ReloadTranscriptEditor();

But you still haven't prvovided any details of what either one looks like or teh actual code that creates them .. which might indicate to us how to deal with it.

Date: Mon, 17 Sep 2012 22:44:56 +0530

rajesh

unread,
Sep 17, 2012, 1:38:34 PM9/17/12
to seleniu...@googlegroups.com
Peter,

I have attached a screenshot of the thee two pop up windows. Hope this would be enough.
A.png

Manoj Hans

unread,
Sep 17, 2012, 1:48:17 PM9/17/12
to seleniu...@googlegroups.com
which IE driver u r using??

rajesh

unread,
Sep 17, 2012, 1:52:01 PM9/17/12
to seleniu...@googlegroups.com
2.25.3.0

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/jVCxJ7aKwKgJ.

Peter Gale

unread,
Sep 17, 2012, 1:53:16 PM9/17/12
to Selenium Users
I can only see one popup window, and it looks like a html page that has been opened in a new window ... you should be able to use the getWindowHandles() and switchTo() methods described on SeleniumHQ.org, then normal WebDriver methods to deal with the html elements of the page.


Date: Mon, 17 Sep 2012 23:08:34 +0530

Manoj Hans

unread,
Sep 17, 2012, 1:58:22 PM9/17/12
to seleniu...@googlegroups.com
I think ur case is like that .....

1.Main window
2. Popup window
3. combo box

m i right??

rajesh

unread,
Sep 17, 2012, 2:00:39 PM9/17/12
to seleniu...@googlegroups.com
I have tried with the same.
But its not working. i was trying window title name in SwitchTo().window().
But none of the things are working.

Peter Gale

unread,
Sep 17, 2012, 2:02:19 PM9/17/12
to Selenium Users
Have you tried getWindowHandles()?


Date: Mon, 17 Sep 2012 23:30:39 +0530

Manoj Hans

unread,
Sep 17, 2012, 2:06:01 PM9/17/12
to seleniu...@googlegroups.com
last one not a combo box...its modal dialog....


try this

String WinNameA=driver.getWindowHandle();//get id of WinNameA
     System.out.println(WinNameA);
     driver.findElement(By.id("Click for pop up")).click();
    
     java.util.Set<String> availableWindows;
     while(true){
      availableWindows=driver.getWindowHandles();
     if(availableWindows.size()==2)
      break;
     }
     
     System.out.println(availableWindows.size());
     String WinNameB=null;
      for(String win:availableWindows){
     if(!win.equals(WinNameA)){
      WinNameB=win;
     driver.switchTo().window(WinNameB);
     System.out.println(driver.getTitle());

     driver.findElement(By.xpath("click for modal dialog")).click();
     java.util.Set<String> availableWindows1;
     while(true){
      availableWindows1=driver.getWindowHandles();
     if(availableWindows1.size()==3)
      break;
     }
     
     System.out.println(availableWindows1.size());
     String modal=null;
      for(String win1:availableWindows1){
     if(!win1.equals(WinNameA)){
      if(!win1.equals(WinNameB)){
      modal=win1;
      }
     }
     driver.switchTo().window(modal);
     System.out.println(driver.getTitle());

    System.out.println(driver.getcurrentUrl());
     }}}


--Manoj Hans

rajesh

unread,
Sep 17, 2012, 2:07:33 PM9/17/12
to seleniu...@googlegroups.com
yes..i have tried this also
Regards,
Rajesh
Mob: 9535268715
Email: raj2...@gmail.com  

Peter Gale

unread,
Sep 17, 2012, 2:10:07 PM9/17/12
to Selenium Users
So show us the code you have tried and any error messages you got ... it' not very helpful just to say it doesn't work without telling us what yo tried.


Date: Mon, 17 Sep 2012 23:37:33 +0530

Manoj Hans

unread,
Sep 17, 2012, 2:20:25 PM9/17/12
to seleniu...@googlegroups.com
show the error msg...most probably exception is unhandlemodaldialog....

but i want to know about the title, console printed all title or not??? 

rajesh

unread,
Sep 18, 2012, 11:19:12 AM9/18/12
to seleniu...@googlegroups.com
Hi,

Please find attached the html page source for the modal pop up window.
below is the code and exception which i am getting while trying with the code to switch the control to the modal pop up window:

1.

String winHandleBefore = driver.getWindowHandle();

            driver.findElement(By.id("btnChangeWorkType")).click();

            Thread.sleep(1000);

            for(String winHandle : driver.getWindowHandles()){

            driver.switchTo().window(winHandle);

        }

            System.out.println(driver.getTitle());

     

            new Select(driver.findElement(By.id("ddlWorkType"))).selectByVisibleText("NOTE");

 

 

 

Exception: org.openqa.selenium.NoSuchElementException: Unable to find element by id using "ddlWorkType"

System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_05'

Driver info: driver.version: ie

 

 

2. Set <String> handles  =driver.getWindowHandles();

        Iterator<String> it = handles.iterator();

      //iterate through your windows

      while (it.hasNext()){

      String parent = it.next();

      String newwin = it.next();

      driver.switchTo().window(newwin);

    

      driver.close();

   

         }

 

This code is switching control to the main window.

Exception : java.util.NoSuchElementException

      at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(Unknown Source)

      at java.util.LinkedHashMap$KeyIterator.next(Unknown Source)

 

 

 

3. Set<String> beforePopUp = driver.getWindowHandles();

            driver.findElement(By.id("btnChangeWorkType")).click();

            Thread.sleep(1000);

            //Get all the window handles in a set

            //get window handles after the click

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

 

                //remove all window handles before the popup

             afterPopup.removeAll(beforePopUp);

            if(afterPopup.size() == 1) {

            popUp = (String) afterPopup.toArray()[0];

             } else {

 

             }

             //switch to popUp

            driver.switchTo().window(popUp);

 

 

Exception : java.lang.NullPointerException: String initializer must be non-null

      at com.sun.jna.WString.<init>(WString.java:23)

 



Regards,
Rajesh

Have you tried getWindowHandles()?

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/T4yljHNDmp8J.
ModalDialogBox.html

Peter Gale

unread,
Sep 18, 2012, 11:48:11 AM9/18/12
to Selenium Users
Rajesh

We need to uinderstand how these lines:
   parent.dialogArguments.ReloadTranscriptEditor();

window.opener.ReloadTranscriptEditor();

create popups, or some other inofrmation to help us understand exactly what they are and how to deal with them.

Nothing in your attachment tells us that that I can see.

Peter


Date: Tue, 18 Sep 2012 20:49:12 +0530
--Forwarded Message Attachment--

Note:- Change of Work Type will Reload the Editor Window.
Work Type: 
                  
   

rajesh

unread,
Sep 18, 2012, 11:54:24 AM9/18/12
to seleniu...@googlegroups.com
In this pop up window, changing the combo box value and clicking on 'Update' button, the first window will be reloaded again.
Clicking on cancel button, will only close the modal pop up window and control will go to the first pop uo window.


Rajesh

Peter Gale

unread,
Sep 18, 2012, 12:01:20 PM9/18/12
to Selenium Users
Rajesh

You've said that several times already and it doesn't help. People here need techical details in order to give you a technical help.

But I give up. Maybe someone else will be able to help.

Peter


Date: Tue, 18 Sep 2012 21:24:24 +0530

Manoj Hans

unread,
Sep 18, 2012, 12:17:09 PM9/18/12
to seleniu...@googlegroups.com
I also can't understand wt rajesh trying to say.....At last if possible for u then show me ur code via team viewer
Otherwise,I also give up


-Manoj Hans

rajesh

unread,
Sep 18, 2012, 12:36:57 PM9/18/12
to seleniu...@googlegroups.com
Please find attached the test script for reference:

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rBsgqaB9mEQJ.
PracticalWebdriver.java

Peter Gale

unread,
Sep 18, 2012, 12:44:10 PM9/18/12
to Selenium Users
Does your test script create the windows dialogs?


Date: Tue, 18 Sep 2012 22:06:57 +0530

rajesh

unread,
Sep 18, 2012, 12:46:36 PM9/18/12
to seleniu...@googlegroups.com
Yes the modal dialog box opens. But the control is not going to this window.

Peter Gale

unread,
Sep 18, 2012, 12:52:23 PM9/18/12
to Selenium Users
No ... your script do not CREATE the windows. It interacts with the browsers with calls some other code which creates the windows. That code is probably what soemone needs to see to help you.

But it won't be me.


Date: Tue, 18 Sep 2012 22:16:36 +0530

rajesh

unread,
Sep 18, 2012, 12:57:28 PM9/18/12
to seleniu...@googlegroups.com
The modal pop up window launches after execution of below line:
driver.findElement(By.id("btnChangeWorkType")).click();
I have attached the test script i am using.

Manoj Hans

unread,
Sep 18, 2012, 1:01:10 PM9/18/12
to seleniu...@googlegroups.com
how can u ensure that u r switching on right window using this code???


            for(String winHandle : driver.getWindowHandles()){

            driver.switchTo().window(winHandle);

rajesh

unread,
Sep 18, 2012, 1:07:46 PM9/18/12
to seleniu...@googlegroups.com
That's what i am asking, how to switch control to the pop up window.
what modification is required. I tried below mentioned codes, but it didn't worked.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/Zgg6-iDdC_IJ.

Manoj Hans

unread,
Sep 18, 2012, 1:11:09 PM9/18/12
to seleniu...@googlegroups.com
try this---

  java.util.Set<String> availableWindows;
     while(true){
    availableWindows=driver.getWindowHandles();
     if(availableWindows.size()==2)
    break;
     }
     
     System.out.println(availableWindows.size());
     String popup=null;
      for(String win:availableWindows){
     if(!win.equals(winHandleBefore)){
     popup=win;
     driver.switchTo().window(popup);

rajesh

unread,
Sep 18, 2012, 1:22:07 PM9/18/12
to seleniu...@googlegroups.com
what about 'winHandleBefore'. this variable has not been initialized in this below code.



To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/MujKF9ba7UgJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Manoj Hans

unread,
Sep 18, 2012, 1:29:21 PM9/18/12
to seleniu...@googlegroups.com
see ur code u will get to know....

Neeraj Sharma

unread,
Sep 19, 2012, 1:16:25 AM9/19/12
to seleniu...@googlegroups.com
Hi Rajesh, I have tried to handle multiple windows for Kotak.com site and here is my code which is running successfully on my machine. Please have a look into this and might you get any clue from there.

public class kotak {

public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://kotak.com");
Thread.sleep(1000);
// save the current window handle.
String parentWindowHandle = driver.getWindowHandle();
//clicking on the secure login button on the home page
driver.findElement(By.xpath("//html/body/div/div[2]/div/div/a/img")).click();
Thread.sleep(100);
 
     WebDriver popup = null;
//saving all windows id in  set
     Set<String> handles = driver.getWindowHandles();
     
     Iterator<String> windowIterator = handles.iterator();
     while(windowIterator.hasNext()) { 
      //moving forward to the next window id 
       String windowHandle = windowIterator.next(); 
    
       popup = driver.switchTo().window(windowHandle);
       Thread.sleep(1000);
     }
       if 
       (popup.getTitle().equals("KMBL Net Banking Login")){
        System.out.println(popup.getTitle());  
       }
       else {
        System.out.println("Driver is not shifted to new window");
       }
       driver.switchTo().frame(0);
       // asserting the heading on the login page and printing the same
    String heading = driver.findElement(By.id("heading")).getText();
    System.out.println(heading);
    //Entering the userId in login page
    driver.findElement(By.xpath("//html/body/form/div/div/div[3]/table/tbody/tr/td/div/table/tbody/tr[2]/td[3]/input")).sendKeys("12345");
    
    // Shifting driver to parent window
    driver.switchTo().window(parentWindowHandle);
    Thread.sleep(100);
    //entering the keyword in the search text box.
    driver.findElement(By.id("searchInputBox")).sendKeys("Neeraj");

Neeraj Sharma

unread,
Sep 19, 2012, 1:22:49 AM9/19/12
to seleniu...@googlegroups.com
Hi Rajesh,

I think you don't need to iterate two times in the below code. Use this code and your code should work fine. 

2. Set <String> handles  =driver.getWindowHandles();

        Iterator<String> it = handles.iterator();

      //iterate through your windows

      while (it.hasNext()){

      String newwin = it.next();

      driver.switchTo().window(newwin);

    

      driver.close();

rajesh

unread,
Sep 19, 2012, 11:10:46 AM9/19/12
to seleniu...@googlegroups.com
 Hi All,

I tried with below code. Its is switching the control to the 1st pop up window and not to the 2nd pop up which is modal pop up window.
I guess nothing wrong with the code. When i am running my test class, the modal pop up window gets opened but the control still goes to 1st pop up window. But while running the same test in debug mode, the modal pop up window doesn't open. I am not getting any exception. Can anyone help me in this.

java.util.Set<String> winHandleBefore = driver.getWindowHandles(); //getWindowHandle();
        driver.findElement(By.id("btnChangeWorkType")).click();
        //je.executeScript("return OpenChangeWorkType()");
        Thread.sleep(2000);
        java.util.Set<String> availableWindows = driver.getWindowHandles();
         while(true){
        availableWindows = driver.getWindowHandles();
         if(availableWindows.size()==2)
        break;
        
         System.out.println(availableWindows.size());
         String npopup = null;
          for(String win:availableWindows){
        
        if(!win.equals(winHandleBefore)){
         npopup=win;
        }
          }
         System.out.println(driver.getTitle());   
         driver.switchTo().window(npopup);



Regards,
Rajesh
  

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/QWZGpstPgRsJ.

Manoj Hans

unread,
Sep 19, 2012, 12:35:36 PM9/19/12
to seleniu...@googlegroups.com
Use this...dont change anything otherwise i wont rectify again...        

 String winHandleBefore = driver.getWindowHandle();
        driver.findElement(By.id("btnChangeWorkType")).click();
        //je.executeScript("return OpenChangeWorkType()");
        Thread.sleep(2000);
         java.util.Set<String> availableWindows;
     while(true){
      availableWindows=driver.getWindowHandles();
     if(availableWindows.size()==2)
      break;
     }
     
     System.out.println(availableWindows.size());
     String popup=null;
      for(String win:availableWindows){
     if(!win.equals(winHandleBefore)){
     popup=win;
     driver.switchTo().window(popup);
        }
         }
         System.out.println(driver.getTitle());    

rajesh

unread,
Sep 20, 2012, 9:07:43 AM9/20/12
to seleniu...@googlegroups.com
I have used the below code but its not working. Still control is going to the home page.


 String winHandleBefore = driver.getWindowHandle();
        driver.findElement(By.id("btnChangeWorkType")).click();
        //je.executeScript("return OpenChangeWorkType()");
        Thread.sleep(2000);
         java.util.Set<String> availableWindows;
     while(true){
      availableWindows=driver.getWindowHandles();
     if(availableWindows.size()==2)
      break;
     }
     
     System.out.println(availableWindows.size());
     String popup=null;
      for(String win:availableWindows){
     if(!win.equals(winHandleBefore)){
     popup=win;
     driver.switchTo().window(popup);
        }
         }
         System.out.println(driver.getTitle());    



To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/6uSlP0bLeXoJ.

Neeraj Sharma

unread,
Sep 21, 2012, 1:23:09 AM9/21/12
to seleniu...@googlegroups.com
Rajesh have you tried to run my code on your machine, any help from there?

rajesh

unread,
Sep 21, 2012, 10:54:04 AM9/21/12
to seleniu...@googlegroups.com
Neeraj! I have tried your code also. But that too is not working for me.


To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rvZsJ5z8vpsJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Neeraj Sharma

unread,
Sep 21, 2012, 11:40:35 AM9/21/12
to seleniu...@googlegroups.com
Copy paste the code as it and run,,and let me know the error if any,,

rajesh

unread,
Sep 21, 2012, 11:45:20 AM9/21/12
to seleniu...@googlegroups.com
As i replied earlier, i am not getting any error. The control is switching to the main 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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/QWZGpstPgRsJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/6uSlP0bLeXoJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/rvZsJ5z8vpsJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 




--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/n9mUD1BmL9wJ.

Neeraj Sharma

unread,
Sep 21, 2012, 11:48:37 AM9/21/12
to seleniu...@googlegroups.com
Try the code which i have pasted...

rajesh

unread,
Sep 21, 2012, 12:13:31 PM9/21/12
to seleniu...@googlegroups.com
Output on console:  Driver is not shifted to new window

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/AWyDZj41YeoJ.

Manoj Hans

unread,
Sep 21, 2012, 12:25:22 PM9/21/12
to seleniu...@googlegroups.com
type ur modal pop up title in if condition. 


 String winHandleBefore = driver.getWindowHandle();
        driver.findElement(By.id("btnChangeWorkType")).click();
        //je.executeScript("return OpenChangeWorkType()");
        Thread.sleep(2000);
         java.util.Set<String> availableWindows;
     while(true){
      availableWindows=driver.getWindowHandles();
     if(availableWindows.size()==2)
      break;
     }
     
     System.out.println(availableWindows.size());
      for(String win:availableWindows){
if ("Type here modal pop up title".equals(driver.switchTo().window(win).getTitle()))
      break;
        }
         }
         System.out.println(driver.getTitle());

Neeraj Sharma

unread,
Sep 21, 2012, 12:26:28 PM9/21/12
to seleniu...@googlegroups.com
If you have tried my code and getting this error then mi?ght be the issue is due to network connectivity. try to increase the thread.sleep time and check the your driver and firefox is at running at same speed.

rajesh

unread,
Sep 22, 2012, 10:54:49 PM9/22/12
to seleniu...@googlegroups.com
Manoj/Neeraj,

I tried with the code shared by you, but it was not working for me.
I tried the below code and strangely its working fine for me. I enclosed all the code inside while block.
Now after clicking on a button, modal dialog box gets closed and a javascript confirmation message comes which has 'yes', 'No' and 'Cancel' buttons. Now i am not able to switch to that confirmation message window. I have tried with Alert alert = driver.switchto().alert();
alert.accept();
But its not working.



Regards,
Rajesh

String winHandleBefore = driver.getWindowHandle(); //getWindowHandle();
        System.out.println(driver.getTitle());
        logger.info(driver.getTitle());

        driver.findElement(By.id("btnChangeWorkType")).click();
        //je.executeScript("return OpenChangeWorkType()");
        Thread.sleep(2000);
        java.util.Set<String> availableWindows = driver.getWindowHandles();
         while(true){
        availableWindows = driver.getWindowHandles();
         if(availableWindows.size()==2)
        break;
        
         System.out.println(availableWindows.size());
         String npopup = null;
          for(String win:availableWindows){
        
        if(!win.equals(winHandleBefore)){
         npopup=win;
        }
          }
         System.out.println(driver.getTitle());   
         driver.switchTo().window(npopup);   // switched control to modal pop up window
        logger.info(driver.getTitle());
        new Select(driver.findElement(By.id("ddlWorkType"))).selectByVisibleText("PROGRESS NOTE");
        driver.findElement(By.id("btnOk")).submit();      // closes the modal dialog box
        }

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/stDgRfRzj78J.

Manoj Hans

unread,
Sep 23, 2012, 2:51:31 AM9/23/12
to seleniu...@googlegroups.com
Rajesh...the below code given by me...how could u say that my code was not working for you????

In this thread , I wont reply more....

rajesh

unread,
Sep 26, 2012, 11:02:25 AM9/26/12
to seleniu...@googlegroups.com
Hi Manoj,

Please don't take in other way. I told that the code is not working in that form.
It is working if i am changing the position of closing brace of while loop at the end of the code.
The same thing i mentioned in the earlier mail.

Regards,
Rajesh

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/AmjhdoR12oQJ.

Manoj Hans

unread,
Sep 26, 2012, 11:53:57 AM9/26/12
to seleniu...@googlegroups.com
wtever.......may be somebody else help u out ...but i wont....

Zhunzar gulhane

unread,
Sep 24, 2017, 10:14:44 AM9/24/17
to Selenium Users
Hi Neeraj,

This is Zhunzar. I am trying to use ICICI bank website, after loading the website i am trying to click on know more hyperlink, which i am able to do in webdriver.
But when i click on "know more" i am getting an pop up and i am trying to shift my control to the pop window, so that i can close the pop up and quit the test.
This is the link "https://loan.icicibank.com/asset-portal/personal-loan/apply-now?WT.mc_id=MCCM_NPQ_Pop&utm_source=MCCM&utm_campaign=PL_NPQ&utm_medium=HP_PopUp"  . In this link if you click on "know more" you will get the pop up. I tried using getwindowhandles and alert class but it is not working for me.

I have pasted my code ....
 
package zhunzar12;

import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class Window2 {
WebDriver driver;
@Test
    public void test() throws InterruptedException
    {
System.setProperty("webdriver.chrome.driver","E://Drivers//chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
Thread.sleep(3000);
//WebDriver popup=null;
Set<String> winid=driver.getWindowHandles();
Iterator<String> itr= winid.iterator();
System.out.println(itr.next());
driver.findElement(By.xpath(".//*[@id='apply-now-page']/div[1]/div/div/a")).click();
Thread.sleep(4000);
winid=driver.getWindowHandles();
System.out.println(winid);
itr=winid.iterator();
String fwin=itr.next();
String swin=itr.next();
System.out.println(fwin);
System.out.println(swin);
driver.switchTo().frame(swin);
driver.findElement(By.xpath(".//*[@id='knowmore']/div/div/div[1]/a")).click();
    driver.switchTo().window(fwin);
driver.quit();
    }

}


Request you to please help me out.

Regards,
Zhunzar

On Saturday, September 15, 2012 at 9:14:37 PM UTC+5:30, Rajesh Ranjan wrote:
Hi,

I am using selenium webdriver to automate a web application.
In the application thee are some 'Modal pop up' windows and some are 'Ajax pop up' windows.
I have tried with:
driver.switchto().window()  and
Alert alert = driver.switchto().alert()
But none of them are working.
Please suggest a solution for this.


Regards,
Rajesh
Email: raj2...@gmail.com  
Reply all
Reply to author
Forward
0 new messages