Example of Handling Multiple Browser Windows inwards Selenium WebDriver

Selenium WebDriver software testing tool has built inwards "WebDriver.switchTo().window()" method available to switch from ane window to unopen to other window hence it is really slow to handle multiple windows inwards webdriver. If you lot remember, We tin purpose "selectWindow" window ascendency inwards selenium IDE software testing tool to direct unopen to other window. If window produce non induce got whatever championship or both window has same championship as well as hence it was really hard to direct other window inwards selenium IDE software testing tool. WebDriver software testing tool has made it really easy. You tin handle multiple windows fifty-fifty if all the windows produce non induce got whatever championship or contains same title.

If you lot wants to operate alongside multiple tabs as well as hence stance THIS POST and wants to operate alongside multiple IFrames as well as hence stance THIS POST.

WebDriver.getWindowHandles()
In WebDriver software testing tool, We tin purpose "WebDriver.getWindowHandles()" to instruct the handles of all opened windows past times webdriver as well as and hence nosotros tin purpose that window handgrip to switch from from ane window to unopen to other window. Example Syntax for getting window handles is every bit bellow.

Set<String> AllWindowHandles = driver.getWindowHandles();

WebDriver.switchTo().window()
WebDriver.switchTo().window() method is useful to switch from ane window to unopen to other window of software spider web application. Example syntax is every bit bellow.

driver.switchTo().window(window2);

Bellow given webdriver representative of switching window volition explicate you lot it deeply. Execute it inwards your eclipse as well as elbow grease to empathize how webdriver produce it.

Copy bellow given @Test method business office of treatment multiple windows of webdriver and supplant it alongside the @Test method business office of representative given on THIS PAGE.(Note : @Test method is marked with pink color in that linked page).

@Test   world void exam () throws InterruptedException    {   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);   driver.findElement(By.xpath("//b[contains(.,'Open New Page')]")).click();      // Get as well as shop both window handles inwards array   Set<String> AllWindowHandles = driver.getWindowHandles();   String window1 = (String) AllWindowHandles.toArray()[0];   System.out.print("window1 handgrip code = "+AllWindowHandles.toArray()[0]);   String window2 = (String) AllWindowHandles.toArray()[1];   System.out.print("\nwindow2 handgrip code = "+AllWindowHandles.toArray()[1]);      //Switch to window2(child window) as well as performing actions on it.   driver.switchTo().window(window2);   driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("My Name");   driver.findElement(By.xpath("//input[@value='Bike']")).click();   driver.findElement(By.xpath("//input[@value='Car']")).click();   driver.findElement(By.xpath("//input[@value='Boat']")).click();   driver.findElement(By.xpath("//input[@value='male']")).click();   Thread.sleep(5000);      //Switch to window1(parent window) as well as performing actions on it.   driver.switchTo().window(window1);   driver.findElement(By.xpath("//option[@id='country6']")).click();   driver.findElement(By.xpath("//input[@value='female']")).click();   driver.findElement(By.xpath("//input[@value='Show Me Alert']")).click();   driver.switchTo().alert().accept();   Thread.sleep(5000);      //Once Again switch to window2(child window) as well as performing actions on it.   driver.switchTo().window(window2);   driver.findElement(By.xpath("//input[@name='fname']")).clear();   driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("Name Changed");   Thread.sleep(5000);   driver.close();         //Once Again switch to window1(parent window) as well as performing actions on it.   driver.switchTo().window(window1);   driver.findElement(By.xpath("//input[@value='male']")).click();   Thread.sleep(5000);      }

VIEW MORE DIFFERENT EXAMPLES OF WEBDRIVER

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post