Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium automation not working for a pop up window

I am using Selenium 2.x WebDriver for the automation of a java project. While the automation proceeds it reaches a page in which, when a submit button is clicked a "pop up window" appears and the automation cannot be proceeded.

Code

public void writeSite(WebDriver driver, ZoneTest zone) throws BiffException, InterruptedException, IOException

    //Creates a new zone for testing

    General.elementClick_xpath(driver, Locators.siteMenuDropBoxXpath);
    General.waitToLoad(General.WAIT_MIN);
    General.elementClick_xpath(driver, Locators.viewSitesButtonXpath);
    General.elementClick_xpath(driver, Locators.viewDataPointDetailsXpath);
    General.waitToLoad(General.WAIT_AVG);

    General.elementClick_xpath(driver, Locators.addZoneXpath);

    General.waitToLoad(General.WAIT_AVG);

    General.inputTextFieldEnter_Id(driver, "name", zone.zoneName);
    General.inputTextFieldEnter_Id(driver, "description",zone.zoneDescription );
    General.inputTextFieldEnter_Id(driver, "urlExtension", zone.urlExtension);
    General.inputTextFieldEnter_Id(driver, "timeSpentThreshold", zone.thresholdTime);
    General.inputTextFieldEnter_Id(driver, "tuningNumber", zone.tuningNumber);

   **General.elementClick_xpath(driver, Locators.createZoneSubmitXpath);**

   //Here a new pop up window apppears. And the following codes 3 lines doesnt work.

    General.inputTextFieldEnter_Id(driver, "active", zone.act);
    General.inputTextFieldEnter_Id(driver, "userid", zone.uid);
    General.elementClick_xpath(driver, Locators.SubmitXpath)
}


public class General 
{
  public static final long WAIT_MICRO = 500;
  public static final long WAIT_MIN = 2000;
  public static final long WAIT_AVG = 5000;
  public static final long WAIT_MAX = 5500;
  public static String baseUrl ="";


  //Method to wait  
  public static void waitToLoad(long milliSeconds) throws InterruptedException {
     Thread.sleep(milliSeconds);
  }

     // Method to load the Url taken from the config.property file

  public static void loadBaseUrl(WebDriver driver){
     baseUrl = PropertyUtility.getProperty("Baseurl");
     driver.get(baseUrl);
     driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
  }

  public static void inputTextFieldEnter_xpath(WebDriver driver, String LocatorId, String ValueToBeEntered) throws InterruptedException {       
     System.out.println("Log in user name_inputTextField_outside if: "+ ValueToBeEntered);
     WebElement inputTextField = driver.findElement(By.xpath(LocatorId));
     General.waitUntilElementVisible(driver, LocatorId);
     inputFieldClear_xpath(driver,LocatorId);
     inputTextField.sendKeys(ValueToBeEntered);     
}

How can I switch the view to new pop up window?

like image 281
Akhil Suresh Avatar asked Sep 29 '14 11:09

Akhil Suresh


1 Answers

If you want to do any operations in pop-up window, here is WebDriver logic to select Pop-up window.

driver.switchTo().window("<window name>");
like image 129
Krishnalal P Avatar answered Oct 31 '22 20:10

Krishnalal P