专注于儿童窗口 - 硒

时间:2015-12-15 13:03:12

标签: java selenium-webdriver automated-tests

使用下面的代码可以识别在父窗口上单击按钮后打开的子窗口,但不能与之交互。 我无法获取子窗口中的按钮文本。

岛上没有错误,只是没有执行所需的操作。

我做错了什么?

Set<String> handles = driver.getWindowHandles();

          String firstWinHandle = driver.getWindowHandle(); 

          String secondWinHandle;

          String winHandle=handles.iterator().next();

          if (winHandle!=firstWinHandle){

          //To retrieve the handle of second window, extracting the handle which does not match to first window handle

          secondWinHandle=winHandle; //Storing handle of second window handle

         //Switch control to new window

          driver.switchTo().window(secondWinHandle);

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

          By tipoTecnologia2 = By.cssSelector("[name='btnClose'][value='Fechar'][type='input']");
         driver.findElement(tipoTecnologia2).click();

            driver.switchTo().activeElement().sendKeys(Keys.TAB);



          }

Window

1 个答案:

答案 0 :(得分:0)

  Set<String> handles = driver.getWindowHandles();

      System.out.println("no of windows" +handles.size());

      String firstWinHandle = driver.getWindowHandle(); 

      String window1=handles.iterator().next();

      String window2=handles.iterator().next();

      if(window1.equals(firstWinHandle)){

          System.out.println("in parent windows.. switiching to child");

          driver.switchTo().window(window2);

      }else{

          driver.switchTo().window(window1);

          System.out.println("switched to second window");

      }

请尝试这个,让我知道你能切换到新窗口。在这里我期待只有两个窗口