2013-08-27 3 views
0

Как закрыть дочерние окна? в Selenium WebDriver - с помощью FunctionalClass Привет, я использую Selenium Web Driver и Frame Work, в моем приложении. Когда я нажимаю наКак закрыть дочерние окна? в Selenium WebDriver - с помощью FunctionalClass

Одна кнопка ссылки, затем будет отображаться детское окно на экране, теперь как Завершить

Ребенок Windows.

public class Reports 
{ 
    public void RPS(WebDriver driver) throws Exception 
    { 
     AllpagesLogins ALP= new AllpagesLogins(); 
     //Clicking on the Reports Menu Btn-- Use for Menu Button upper and down 
     WebElement element1 = driver.findElement(By.id(ALP.RP_Reports_MenuBtn_ID)); 
     ((JavascriptExecutor) driver).executeScript("arguments[0].click()", element1); 
     System.out.println("Clicked on the Reports Menu Btn"); 
     Thread.sleep(1000); 
     //Clicking on the Particular Link Button 
     if(driver.findElement(By.linkText("Congratulations Sandeep Pushpala!!!")).isDisplayed()) 
     { 
      System.out.println("Link Button is Displayed"); 
      driver.findElement(By.linkText("Congratulations Sandeep Pushpala!!!")).click(); 
      System.out.println("Clicked on the Link Button Which is Displayed"); 
      Thread.sleep(2000); 
     } 
     else 
     { 
      System.out.println("Link Button is Not Displayed"); 
     } 
     //clicking on the First Link Button, It will display the First Child Window 
     ////////////////////////////11111111111111 
     if(driver.findElement(By.id(ALP.RP_TotalRecipients_LnkBtn_ID)).isEnabled()) 
     { 
      System.out.println("LnkBtnTotalRecipientsID Link Button is Enabled"); 
      driver.findElement(By.id(ALP.RP_TotalRecipients_LnkBtn_ID)).click(); 
      System.out.println("Clicked on the LnkBtnTotalRecipientsID Button"); 
      Thread.sleep(2000); 
     } 
     else 
     { 
      System.out.println("Link Button is Total Recipients is Not Displayed"); 
     } 
     //clicking on the Second Link Button, It will display the Second Child Window 
     ////////////////////////////2222222222222222222 
     if(driver.findElement(By.id(ALP.RP_SuccessfullRecipientsData_LnkBtn_ID)).isEnabled()) 
     { 
      System.out.println("SuccessfullRecipientsDataID Link Button is Enabled"); 
      driver.findElement(By.id(ALP.RP_SuccessfullRecipientsData_LnkBtn_ID)).click(); 
      System.out.println("Clicked on the LinkSuccessfullRecipientsDataID Button"); 
      Thread.sleep(2000); 
     } 
     else 
     { 
      System.out.println("Link Button is SuccessfullRecipientsDataID is Not Displayed"); 
     } 
     //clicking on the Third Link Button, It will display the Third ![enter image description here][1]Child Window 
     ///////////////////////////////333333333333333333333333333 
     if(driver.findElement(By.id(ALP.Rp_NotSucessfullRecipientsData_LnkBtn_ID)).isEnabled()) 
     { 
      System.out.println("NotSucessfullRecipientsDataID Link Button is Enabled"); 
      driver.findElement(By.id(ALP.Rp_NotSucessfullRecipientsData_LnkBtn_ID)).click(); 
      System.out.println("Clicked on the LinkNotSucessfullRecipientsDataID Button"); 
      Thread.sleep(2000); 
     } 
     else 
     { 
      System.out.println("Link Button is Successfully Recipients Data ID is Not Displayed"); 
     } 
     for Closing the Child Windows I am Using This Code 
     //Closing the First Child Window 
     driver.close(); 
     System.out.println("First Child Window is Closed"); 
     Thread.sleep(2000); 
     //Closing the Second Child Window 
     driver.close(); 
     System.out.println("Second Child Window is Closed"); 
     Thread.sleep(2000); 
     //Closing the Third Child Window 
     driver.close(); 
     System.out.println("Third Child Window is Closed"); 
     Thread.sleep(2000); 

ответ

0

Вы должны переключиться на другое окно с помощью switchTo() method:

String firstWindow = driver.getWindowHandle(); 
// execute code to open a second window 

// close the first window 
driver.switchTo().window(firstWindow).close(); 
+0

Используя этот код, я закрываю родительское окно, но мне нужно закрыть окно для детей, – user2707135

1

У меня есть служебный метод, чтобы переключиться на требуемое окно, как показано ниже

public class Utility 
{ 
    public static WebDriver getHandleToWindow(String title){ 

     //parentWindowHandle = WebDriverInitialize.getDriver().getWindowHandle(); // save the current window handle. 
     WebDriver popup = null; 
     Set<String> windowIterator = WebDriverInitialize.getDriver().getWindowHandles(); 
     System.err.println("No of windows : " + windowIterator.size()); 
     for (String s : windowIterator) { 
      String windowHandle = s; 
      popup = WebDriverInitialize.getDriver().switchTo().window(windowHandle); 
      System.out.println("Window Title : " + popup.getTitle()); 
      System.out.println("Window Url : " + popup.getCurrentUrl()); 
      if (popup.getTitle().equals(title)){ 
       System.out.println("Selected Window Title : " + popup.getTitle()); 
       return popup; 
      } 

     } 
       System.out.println("Window Title :" + popup.getTitle()); 
       System.out.println(); 
      return popup; 
     } 
} 

Он будет считать вас в желаемое окно, когда заголовок окна передается как параметр. В вашем случае вы можете это сделать.

, а затем снова перейти к родительскому окну, используя тот же метод,

Webdriver parentDriver = Utility.getHandleToWindow("titleOfParentWindow"); 

Этот метод работает эффективно при работе с несколькими окнами.

+0

это метать ошибку Msg ... – user2707135

+0

Пожалуйста, разместите свой код и ошибку messaga –

Смежные вопросы