0

I have a scenario as below

1. Login to the application
2. click on a button (say Buy)
3. This will take me to a new window opened with a new URL automatically
4. Perform actions in the new window
5. Quit

Kindly please provide the exact code to work on this. I tried with the available code that exists in the website which didnt work for me

Meghasri
  • 103
  • 1
  • 7
  • 13
  • http://toolsqa.com/selenium-webdriver/switch-commands/ – A user Jun 01 '17 at 12:57
  • I hope the above code should work for you. Lets you to switch to child window and perform operations. also it has practise example which gives tip to toe information about switching between windows – A user Jun 01 '17 at 12:57
  • Please see https://stackoverflow.com/help/how-to-ask . At least you should mention what steps you took that didn't work out for you and what was the error that crept up. Simply copying and pasting any problem with not get you anywhere and would attract down votes. – demouser123 Jun 01 '17 at 12:59
  • 1
    Am new to selenium and not from java backgroud. So would require help from the experts like you. The link which u provided helped me and resolved my issue. Thank you – Meghasri Jun 02 '17 at 07:08

1 Answers1

0

You can try on following pattern:-

   Webdriver driver = new ChromeDriver();
   driver.get("URL of application");
   driver.findElement(By.id("username").sendKeys("user1");
   driver.findElement(By.id("password").sendKeys("pass1");
   driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
   driver.findElement(By.xPath("xpath of button").click();

//now you can switch to pop-up and accordingly accept or dismiss it

   driver.switchTo().alert().accept();

   driver.quit();

In case you provide the SO community the URL of application then only complete code can be provided.

Deepak
  • 110
  • 2
  • 16
  • I think you mis-understood the OP's question, as an alert is not coming into play here. I think you might also not understand implicit waits correctly. The implicit wait should be defined after driver initialization, and you'd want more than three seconds. Your first two findelement statements could fail because there is no implicit wait defined. – Bill Hileman Jun 01 '17 at 14:49
  • @Bill, I very much got the question and as the statement of Meghasri was in general terms so my answer was in general terms so that she can enhance it further as per need. As far as 2 seconds of implicit wait is concerned it is a kind of example, since we don't know about application and its behavior so I just entered any number. For first 2 findelements wait would require if page refreshes otherwise no need of wait. – Deepak Jun 02 '17 at 08:08