Showing posts with label selenium popup. Show all posts
Showing posts with label selenium popup. Show all posts

Wednesday, July 25, 2012

How to handle popup using Selenium RC?

Handling Popup's using Selenium RC:
 
public void testPopup() throws Exception {
    selenium.open("http://yoursitename/page.jsp");
    selenium.click("//img[@alt='Share']");
    selenium.waitForPopUp("_blank", "30000");
    selenium.selectWindow("windowId");
    verifyTrue(selenium.isTextPresent("Recommend to a friend"));
    selenium.close();
} 

How to handle popups in WebDriver

public boolean testNewWindow(){
 String currentHandle = driver.getWindowHandle();
 Set handles = driver.getWindowHandles();
 handles.remove(currentHandle);
 if (handles.size() > 0) {
 try{
 driver.switchTo().window(handles.iterator().next());
 return true;
 }
 catch(Exception e){
 System.out.println(e.getMessage());
 return false;
 }
 }
 System.out.println("Did not find window");
 return false;
 }