我试图使用TestNG访问VCM中的二级弹出窗口,即我点击"添加"父窗口上的按钮然后打开然后我有其他字段要添加到子内容中但是我无法选择子内容窗口。
这是我的代码:
selenium.open("http://xyz.com/AppConsole");
selenium.type("name=j_username", "username");
selenium.type("name=j_password", "password!");
selenium.click("id=vign-login-button");
selenium.waitForPageToLoad("30000");
selenium.click("id=href_consoleMenus30");
selenium.waitForPageToLoad("30000");
selenium.click("link= Contents");
selenium.waitForPageToLoad("30000");
selenium.click("id=href_VignConsoleForm");
selenium.waitForPopUp("createContentInstance_undefined", "30000");
selenium.selectWindow("name=createContentInstance_undefined");
selenium.click("link=XYZ");
selenium.waitForPageToLoad("30000");
selenium.click("id=o12_hierarchyBrowserForm");
selenium.click("name=cmdOK");
selenium.waitForPageToLoad("30000");
selenium.type("id=ce_f508VgnVCM____", "Testing");
selenium.select("id=ce_060859310VgnVCM____", "label=Counting");
verifyTrue(selenium.isTextPresent("Forms"));
selenium.click("name=coe_relator_butn_add_2468d");
selenium.waitForPopUp("Add/Edit", "90000");
selenium.selectWindow("Add/Edit");
verifyEquals(selenium.getTitle(), "Add/Edit");
答案 0 :(得分:1)
我认为你可以修改代码如下&它可以正常工作。
selenium.click("name=coe_relator_butn_add_2468d");
try{
Thread.sleep(5000);
}catch(Exception e){
}
String titles = selenium.getAllWindowTitles();
int i =0;
while(i<titles.length){
if(titles[i].equalsIgnoreCase("Add/Edit"))
break;
i++;
}
selenium.selectWindow(titles[i]);
答案 1 :(得分:0)
我会与您分享帮助我的方法(我使用selenium webDriver + java):
//Store the current window handle
String winHandleBefore = driver.getWindowHandle();
//Perform the click operation that opens new window
fluentWait(By.xpath("....")).click();
driver.manage.timeouts.implicitWait(2,TimeUnit.SECONDS);
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
String winHandleAfter = driver.getWindowHandle();
// Perform the actions on new window
driver.findElement(By.id("nav_aHighlight")).click();
//Close the new window, if that window no more required
driver.close();
//Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);
//continue with original browser (first window)
.......