Showing posts with label New Window. Show all posts
Showing posts with label New Window. Show all posts

December 8, 2014

Working with Multiple windows using selenium webdriver

December 08, 2014 0
Working with Multiple windows using selenium webdriver
In this blog post i am trying to address easiest way to handle multiple windows.

Selenium webdriver has mechanism to identify windows.

getWindowHandle() ---
Return an opaque handle to this window that uniquely identifies it within this driver instance. This can be used to switch to this window at a later date.

getWindowHandles()
Return a set of window handles which can be used to iterate over all open windows of this WebDriver instance by passing them to switchTo().WebDriver.Options.window()


In this example script will perform some actions on main window, after clicking a link it will open a new window and webdriver will switch to child window and perform actions. Once the actions are done on child window it will close child window and switch back to parent window.

Here is the code..

July 25, 2011

Working on New Window

July 25, 2011 2
Working on New Window

Below example is to:
  • open the new window by clicking on one link in Main window, 
  • performing some operations in pop up window,
  • then close the pop up window,
  • and operate some function in main window again.

Program:

package one;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

public class Newwindowselenium extends SeleneseTestCase {
public SeleniumServer ss;
@Before
public void setUp() throws Exception {
ss=new SeleniumServer();
ss.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.bitmotif.com/");
selenium.start();
}

@Test
public void testNewwindowselenium() throws Exception {
// open the URL http://www.bitmotif.com/test-page-for-selenium-remote-control/
selenium.open("/test-page-for-selenium-remote-control/");
// Maximizing the main window
selenium.windowMaximize();
// Click on the link This link opens a popup
selenium.click("link=This link opens a popup");
selenium.waitForPopUp("popup", "30000");
// Select the popup window 
selenium.selectWindow("name=popup");
// Click the link About on popup window 
selenium.click("link=About");
selenium.waitForPageToLoad("30000");
// Close the popup window 
selenium.close();
// back to the main window
selenium.selectWindow("null");
// Click on the link This link goes to another page
selenium.click("link=This link goes to another page");
selenium.waitForPageToLoad("30000");
Thread.sleep(10000);
}

@After
public void tearDown() throws Exception {
selenium.stop();
ss.stop();
}
}