Switching in multiple browser windows in Webdriver

Source: Internet
Author: User
Tags testng

package webdriver;import java.util.logging.logger;import org.openqa.selenium.keys;import  org.openqa.selenium.webdriver;import org.openqa.selenium.firefox.firefoxdriver;import  org.openqa.selenium.interactions.actions;import org.testng.annotations.afterclass;import  Org.testng.annotations.beforeclass;import org.testng.annotations.test;/** *  * change  window in multi browser windows * */public class testwebdriver2  {private static final logger logger = logger.getlogger ( TestWebDriver2.class.getName ());p rivate webdriver webdriver; @BeforeClasspublic  void  Beforeclass () {webdriver = new firefoxdriver ();} @Testpublic  void f () {//open the first window//we have basic  Authentication, so specify username/password in the urlwebdriver.get ("Http://leizhen:[emaiL protected]:2001/httpadmin "); Logger.info (Webdriver.gettitle ()); String currentwindow = webdriver.getwindowhandle ();//open a new windowactions  action = new actions (Webdriver); Action.keydown (Keys.control). SendKeys ("n"). Perform ();// Change to the new opened windowfor (string window :  Webdriver.getwindowhandles ()) {if (!window.equals (Currentwindow)) {Webdriver.switchto (). window (window); break;}} Webdriver.get ("Http://leizhen:[email protected]:2001/httpadmin"); Logger.info (WebDriver.getTitle ());// Change back to the first windowwebdriver.switchto (). window (Currentwindow); logger.info (Webdriver.gettitle ());} @AfterClasspublic  void afterclass () {webdriver.quit ();}}


Switching in multiple browser windows in Webdriver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.