2017-05-31 10 views
0

私のアプリケーションでは、大きなグランドチャイルドウィンドウを処理しています。 WindowsはウィンドウAのような再帰的な方法で来ている - >ウィンドウBが開きます - > Bをクリック - >ウィンドウCが開く - > Cウィンドウをクリック - >ウィンドウDが開きます。 私はListにウィンドウを保存していて、if、else条件では挿入を維持できるが、コードを実行している間にすべてのウィンドウに切り替わり、ときどき偉大な子ウィンドウに切り替わらないことがある。私のコードは以下のように言及しています。セレンでセレンのwebdriverでグレートチャイルドウィンドウを処理する方法

public class DDE_finnone { 


WebDriver driver; 
WebDriverWait wait; 
String app_id= "1894562"; 

@BeforeTest 
public void setupapplication(){ 

    File filepath = new File("C:\\Automation_Softwares\\IEDriverServer\\IEDriverServer.exe"); 

    System.setProperty("webdriver.ie.driver", filepath.getAbsolutePath()); 

    driver = new InternetExplorerDriver(); 

    java.util.ResourceBundle.clearCache(); 

    wait = new WebDriverWait(driver, 20); 

    driver.get("http://retail.herofincorp.com:7031/finnsso/gateway/SSOGateway?requestID=7000002"); 
} 

@Test 
public void DDE() throws Throwable{ 

    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); 

    /*---------------------------------- CAS MAIN SCREEN ------------------------*/ 

    List<String> browsertabs = new ArrayList<String>(driver.getWindowHandles()); 

    System.out.println(browsertabs); 

    driver.switchTo().window(browsertabs.get(0)); 

    driver.findElement(By.name("TxtUID")).sendKeys("testname"); 

    driver.findElement(By.name("TxtPWD")).sendKeys("Testpwd"); 

    driver.findElement(By.name("DataAction")).click(); 

    // Screenshotpath = fn_screenshot(Screenshotpath); 

    try { 

     if (wait.until(ExpectedConditions.alertIsPresent()) != null) { 

      String alertmessage = driver.switchTo().alert().getText(); 

      System.out.println(alertmessage); 

     } 
    } catch (NoAlertPresentException e) { 
     e.printStackTrace(); 
    } 

    // Screenshotpath = fn_screenshot(Screenshotpath); 

    driver.switchTo().alert().accept(); 

    driver.findElement(By.name("btnCAS")).click(); 

    driver.switchTo().window(browsertabs.get(0)); 

    /*-------------------------- Retail Screen ----------------------*/ 

    List<String> FinnoneCAS1 = new ArrayList<String>(driver.getWindowHandles()); 

    Collections.sort(FinnoneCAS1); 

    System.out.println(FinnoneCAS1); 

    driver.switchTo().window(FinnoneCAS1.get(0)); 

    String title5 = driver.getTitle(); 

    System.out.println(title5); 

    if (driver.getTitle().equalsIgnoreCase("Finnone SSO")) { 

     driver.switchTo().window(FinnoneCAS1.get(1)); 

     System.out.println(driver.getTitle()); 
    } 

    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("frameForwardToApp")); 

    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("banner")); 

    WebElement areasection = driver.findElement(By.id("selBranch")); 

    areasection.clear(); 

    Thread.sleep(1000); 

    areasection.sendKeys("delhi"); 

// Thread.sleep(2000); 

    areasection.sendKeys(Keys.TAB); 

    Thread.sleep(3000); 

// Screenshotpath = fn_screenshot(Screenshotpath); 

    driver.switchTo().parentFrame(); 

    driver.switchTo().frame("contents"); 

    Actions move_AutoLoan1 = new Actions(driver); 

    WebElement Auto_loan1 = driver.findElement(By.linkText("Auto Loan")); 

    move_AutoLoan1.moveToElement(Auto_loan1).build().perform(); 

    WebElement DDEsearch = driver.findElement(By.linkText("Detail Data Entry")); 

    wait.until(ExpectedConditions.visibilityOf(DDEsearch));  

// WebElement allsearch = driver.findElement(By.linkText("All")); 

// wait.until(ExpectedConditions.visibilityOf(allsearch)); 

    DDEsearch.click(); 

    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("main")); 

    WebElement searchappId = driver.findElement(By.id("txtApplication")); 

    wait.until(ExpectedConditions.visibilityOf(searchappId)); 

    // Excel should start 

    searchappId.sendKeys(app_id); 

// Screenshotpath = fn_screenshot(Screenshotpath); 

    Thread.sleep(1000); 

    WebElement searchbtn = driver.findElement(By.name("btnSearch")); 

    wait.until(ExpectedConditions.visibilityOf(searchbtn)); 

    searchbtn.click(); 

    WebElement linkappid = driver.findElement(By.xpath("//table[@class='TABLEATTRIBUTES']/tbody/tr[2]/td[1]/a")); 

    wait.until(ExpectedConditions.visibilityOf(linkappid)); 

    linkappid.click(); 

    driver.switchTo().window(FinnoneCAS1.get(0)); 

    System.out.println(driver.getTitle()); 


    /*-------------- DDE ------------------------------------*/ 

    List<String> DDEscreen = new ArrayList<String>(driver.getWindowHandles()); 

    Collections.sort(DDEscreen); 

    System.out.println(DDEscreen); 

    driver.switchTo().window(DDEscreen.get(2)); 

    System.out.println(DDEscreen.get(2)); 

    String title2 = driver.getTitle(); 

    System.out.println(title2); 

    if (title2.equalsIgnoreCase("Finnone SSO")) { 

     driver.switchTo().window(DDEscreen.get(1)); 

     System.out.println(driver.getTitle()); 

    } else if (driver.getTitle().equalsIgnoreCase("Finnone CAS")) { 

     driver.switchTo().window(DDEscreen.get(0)); 

     System.out.println(driver.getTitle()); 
    } 

    WebElement demographic = driver.findElement(By.id("apy_b0i2text")); 

    wait.until(ExpectedConditions.visibilityOf(demographic)); 

    demographic.click(); 

    WebElement customername = driver.findElement(By.xpath("//table[@class='TABLEATTRIBUTES']/tbody/tr[2]/td[1]/a")); 

    wait.until(ExpectedConditions.visibilityOf(customername)); 

    customername.click(); 

    WebElement personaltab = driver.findElement(By.id("apy_b1i1font")); 

    wait.until(ExpectedConditions.visibilityOf(personaltab)); 

    System.out.println(personaltab.getText()); 

    WebElement qualification = driver.findElement(By.id("selEduQualification")); 

    wait.until(ExpectedConditions.visibilityOf(qualification)); 

    qualification.sendKeys("Graduate"); 

    qualification.sendKeys(Keys.TAB); 

    /*------------ Education window ------------*/ 

    List<String> educationwindow = new ArrayList<String>(driver.getWindowHandles()); 

    Collections.sort(educationwindow); 

    System.out.println(educationwindow); 

    driver.switchTo().window(educationwindow.get(3)); 

    String title6 = driver.getTitle(); 

    System.out.println(title6); 

    if (title6.equalsIgnoreCase("1894562-----NISHANT  OMAR")) { 

     driver.switchTo().window(educationwindow.get(0)); 

     System.out.println(driver.getTitle()); 

    } else if (driver.getTitle().equalsIgnoreCase("Finnone SSO")) { 

     driver.switchTo().window(educationwindow.get(1)); 

     System.out.println(driver.getTitle()); 

    } else if (driver.getTitle().equalsIgnoreCase("Finnone CAS")) { 

     driver.switchTo().window(educationwindow.get(2)); 

     System.out.println(driver.getTitle()); 
    } 

    WebElement searchcriteriaGo = driver.findElement(By.name("B1")); 

    wait.until(ExpectedConditions.visibilityOf(searchcriteriaGo)); 

    searchcriteriaGo.click(); 

    driver.switchTo().window(educationwindow.get(0)); 

    /*-----------------Return from Education Window -----------------------*/ 

    List<String> returneducationdetails = new ArrayList<String>(driver.getWindowHandles()); 

    Collections.sort(returneducationdetails); 

    System.out.println(returneducationdetails); 

    driver.switchTo().window(returneducationdetails.get(2)); 

    System.out.println(returneducationdetails.get(2)); 

    String title21 = driver.getTitle(); 

    System.out.println(title21); 

    if (title21.equalsIgnoreCase("Finnone CAS")) { 

     driver.switchTo().window(returneducationdetails.get(0)); 

     System.out.println(driver.getTitle()); 

    } else if (driver.getTitle().equalsIgnoreCase("Finnone SSO")) { 

     driver.switchTo().window(returneducationdetails.get(1)); 

     System.out.println(driver.getTitle()); 
    } 

} 
+0

次の情報を提供することを検討できますか?1. Seleniumバージョン? 2. IEDriverServerのバージョン? 3. IEのバージョン? 4.エラースタックトレース。ありがとう – DebanjanB

答えて

0

には窓内の任意の階層はありません。親ウィンドウと子ウィンドウは、私たちの慣習のためだけに名前が付けられています。しかし、セレンの視点からは、すべてがちょうど別のウィンドウです。コードの下

は、いくつかのアイデアを提供し、

//Get the current window address 
Set<String> parent = driver.getWindowHandle(); 

//Get the all window addresses that are opened by selenium. This includes the parent window too 
Set<String> all = driver.getWindowHandles(); 


//Assume this is the element you need to interact and it is present in some window. 
String XPATH = ".//"; 

//Now iterate through all windows and search for the element you need to interact with. 
for(String now:all) 
{ 

    driver.switchTo().window(now); 
    if(driver.findElements(By.xpath(XPATH)).size()>0) 
    { 
     System.out.println("Element found in the window "+now+ " "+driver.getTitle()); 
     //DO YOUR ACTUAL STUFF 
    } 
} 

が、これはあなたのお役に立てば幸いです。ありがとう。

+0

ありがとうSanthosh、しかし私はリストがセットよりも信頼できると思います。 –

+1

リストは重複している可能性がありますが、重複はありません。 –

+0

リストには重複した値が格納されているかもしれないがWindowsの場合には同意する。ウィンドウID /コードは実行時に一意的に生成されるため、少なくとも挿入と出力の順序を維持するために3つ以上のウィンドウのリストとしてウィンドウを保存できるとき、このロジックを使用していますが、7-8回の再帰的な子ウィンドウが来ているために失敗することがあります。私はSetを使用しましたが、Listと同様に動作しませんでした。同じスクリプトを常に成功させるために、別のソリューションを提供してください。 –

関連する問題