3

我正在尝试使用 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");
4

2 回答 2

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]);
于 2012-10-30T08:46:43.310 回答
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)
.......
于 2012-10-29T17:38:25.570 回答