Will anyone please provide how to write selenium testing code for login popup window for example like in paytm site. When click on login button, it opens a popup window. In that we have to write code to enter username and password and then login.

  • 1
    What effort you did? Did you try to write code? – Helping Hands Mar 12 '15 at 8:52
  • 2
    Most online tutorials start with automating a login screen. – Niels van Reijmersdal Mar 12 '15 at 9:41

Try the Selenium IDE

  • Record your steps
    • Open web-page
    • Click login button
    • Select window
    • Fill in fields
    • Submit
  • Export recording as code to Java or Python

Also read other questions like "How does one get started with web test automation using Selenium?" or Google for some training video's to get you started.

Update Latest version of Selenium IDE does not support exporting, check this: How to export test cases in the latest selenium IDE

| improve this answer | |

Most of the popup are iframe. Hence you need to switch to the login iframe in order to enter the username and passwords as per your requirements.

Please try using following driver.SwitchTo().Frame(FrameName);

Where Framename can be 0 - 1 and so on..

| improve this answer | |

You can do this by following

  1. click on the login button

  2. use the command -> d.switchTo().activeElement();

Here 'd' is the Webdriver instance

Also you may check if there is any frame in the pop up or not. Because you have to switch to the pop up and then iframe.

Hope it helped :)

| improve this answer | |
  • Does this really help the person asking the question? Is this really what s/he was looking for? First you should be asking for clarification as to what exactly did they try out and where they are stuck? – IAmMilinPatel Jul 10 '15 at 17:16

Try this! Use paytm URL instead of linkedin

public void testlinkedin() throws Exception {
driver.get("https://www.linkedin.com/");  //Use your web URL
driver.findElement(By.linkText("Sign Up")).click();

Set <String>handles = driver.getWindowHandles();//To handle multiple windows
firstWinHandle = driver.getWindowHandle();
String winHandle=handles.iterator().next();
if (winHandle!=firstWinHandle){

driver.switchTo().window(secondWinHandle);   //Switch to popup window


Make sure to declare these string variables as,

public String firstWinHandle;  
public String secondWinHandle; 
| improve this answer | |

Below code snippet works for me :-

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

    String parent = it.next();
    String child = it.next();


    //perform actions on child window
    //perform actions on child window

    driver.close(); // only for child wondow


    //perform actions on parent window
    //perform actions on parent window

    driver.quit(); // After execution of main thread and for parent window
| improve this answer | |

Agreed with above steps. You will also need to add script to handle the pop-up, drive switch. Add driver switch before steps for pop-up window. driver.switchTo().window(window name") This will help you: http://santoshsarmajv.blogspot.com/2012/04/how-to-switch-control-to-pop-up-window.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.