-1

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.

Niels van Reijmersdal
32.7k4 gold badges59 silver badges125 bronze badges
asked Mar 12, 2015 at 8:06
2
  • 1
    What effort you did? Did you try to write code? Commented Mar 12, 2015 at 8:52
  • 2
    Most online tutorials start with automating a login screen. Commented Mar 12, 2015 at 9:41

6 Answers 6

2

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

answered Mar 12, 2015 at 9:39
0

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

answered Mar 18, 2015 at 14:31
0

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 :)

answered Jul 3, 2015 at 9:18
1
  • 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? Commented Jul 10, 2015 at 17:16
0

Try this! Use paytm URL instead of linkedin

@Test
public void testlinkedin() throws Exception {
driver.get("https://www.linkedin.com/"); //Use your web URL
driver.findElement(By.linkText("Sign Up")).click();
driver.findElement(By.cssSelector("button.fb-btn")).click();
Thread.sleep(3000);
Set <String>handles = driver.getWindowHandles();//To handle multiple windows
firstWinHandle = driver.getWindowHandle();
handles.remove(firstWinHandle);
String winHandle=handles.iterator().next();
if (winHandle!=firstWinHandle){
 secondWinHandle=winHandle;
driver.switchTo().window(secondWinHandle); //Switch to popup window
Thread.sleep(2000);
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys("Username");
driver.findElement(By.id("pass")).clear();
driver.findElement(By.id("pass")).sendKeys("Password");
driver.findElement(By.id("u_0_2")).click();
driver.findElement(By.name("__CONFIRM__")).click();}

Make sure to declare these string variables as,

public String firstWinHandle; 
public String secondWinHandle; 
answered Oct 23, 2015 at 9:27
3
  • Why are you using a sleep instead of an explicit wait for By.id("email")? The page could be faster then 2 seconds. Now you are waiting for no reasons, or it could be just a bit slower, now the test fails. This could lead to a flickering test. Commented Oct 23, 2015 at 12:40
  • @NielsvanReijmersdal Thanks for the suggestion! Can you elaborate a bit more how can i modify my code to use explicit wait? Commented Oct 23, 2015 at 13:01
  • stackoverflow.com/questions/30986604/… and sqa.stackexchange.com/questions/12583/… Commented Oct 23, 2015 at 13:03
0

Below code snippet works for me :-

 Set <String> handles =driver.getWindowHandles();
 Iterator<String> it = handles.iterator();
 String parent = it.next();
 String child = it.next();
 driver.switchTo().window(child);
 //perform actions on child window
 //perform actions on child window
 driver.close(); // only for child wondow
 driver.switchTo().window(parent);
 //perform actions on parent window
 //perform actions on parent window
 driver.quit(); // After execution of main thread and for parent window
answered Jul 6, 2016 at 11:30
0

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

Glorfindel
3161 gold badge7 silver badges15 bronze badges
answered Mar 16, 2015 at 15:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.