简体   繁体   中英

Windows handling in Selenium webdriver using java

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM