首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在selenium中处理子窗口

在selenium中处理子窗口
EN

Stack Overflow用户
提问于 2012-10-29 20:46:07
回答 2查看 3.8K关注 0票数 3

我正在尝试使用TestNG访问VCM中的二级弹出窗口,即我点击了父窗口上的“添加”按钮,然后它打开了,然后我有其他字段要添加到子内容中,但我无法选择子内容窗口。

下面是我的代码:

代码语言:javascript
复制
    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");
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-30 16:46:43

我认为您可以按如下方式修改代码&它可能工作得很好。

代码语言:javascript
复制
   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
EN

Stack Overflow用户

发布于 2012-10-30 01:38:26

我将与您分享对我有帮助的方法(我使用selenium webDriver+java):

代码语言:javascript
复制
    //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)
.......
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13121921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档