在我的應用程序中,我正在處理巨大的兒童窗口。 Windows以遞歸方式進入,如窗口A->單擊A - >窗口B打開 - >單擊B - >窗口C打開 - >單擊C窗口 - >窗口D打開。 所以我在列表中存儲窗口和使用如果,否則,如果條件,以便插入可以維持,但執行代碼時,它切換到所有窗口,有時它不會切換到偉大的子窗口。我的代碼如下所述。如何在硒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());
}
}
您能否考慮提供以下信息:1.硒版本? 2. IEDriverServer版本? 3. IE版本? 4.錯誤堆棧跟蹤。謝謝 – DebanjanB