July 25, 2011

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();
}
}

2 comments:

  1. Chosing a menu from the main menu, the page is refreshed having data for the accessed menu (no new window pops up) and now i want to go down in the page and click on a link. How can I do this using Selenium RC? Because if i try selenium.selectFrame("down") and than selenium.click("[the respective address]"); nothing happens, error message is displayed in eclipse,saying that the accessed data can not be found, although it exist (because with seleniu.selectFrame("down"); the programm does not know where ot go). Exist another command to go in a page down, than selenium.selectFrame("down");?
    Thank You!

    ReplyDelete
  2. Hello Naga,

    I am unable to capture the pop up window focus and above script works only till open pop up, after which it dosen't, can u help me fo rthe same

    Thanks,
    Riyazul

    ReplyDelete