Selenium automation not working for popup

I am using Selenium 2.x WebDriver to automate a Java project. While the automation continues, it reaches a page on which, when the submit button is pressed, a “pop-up window” appears and the automation cannot be continued.

the 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 to switch a view to a new popup?

+4
source share
3 answers

If you want to perform any operation in a popup, here is the logic of WebDriver to select a popup.

driver.switchTo().window("<window name>");
+8
source

, . , .

: ws = driver.get windowshandles();

    Iterator itr=ws.iterate();

    String W1=(String)itr.next();

    String W2=(String)itr.next();
.

driver.switchTo() (W1);

()

.

driver.switchTo() (W2);

() ......

+1

, , . .

driver.switchTo().window("Window ID");

.

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

, , .

String vBaseWindowHandle = driver.getWindowHandle();
    Set<String> windows = driver.getWindowHandles();

    for(String temp : windows)
    {
        driver.switchTo().window(temp);
    }

    // Do code for new window

    driver.close();     
    driver.switchTo().window(vBaseWindowHandle);

For additional information related to the processing of windows and pop-ups, follow the link below https://trickyautomationworld.blogspot.in/2018/03/how-to-handle-windows-in-selenium.html https: //trickyautomationworld.blogspot .in / 2018/03 / how-to-handle-popup-in-selenium.html

0
source

All Articles