0

我正在尝试切换到一个新窗口,当我单击债务定价模板时会显示该窗口。但我无法做到这一点,因此我无法继续进行进一步的脚本编写......问题是我不知道我应该传递什么,switchTo.window()因为定价批准网关窗口显示并且以下是 HTML对于新窗口:

<*h1 class="pageType noSecondHeader">Pricing Approval Gateway<*/h1>

以下是代码:

LoginPage2.driver.findElement(By.linkText("TEST ORG")).click();

System.out.println("3.Select Dept pricing template button from the organization detail page.");

if(LoginPage2.driver.findElement(By.name("debt_pricing_template")).isDisplayed())

System.out.println("User should able to navigate to Dept pricing template and template display few question, user have answer these question for further navigation.");

LoginPage2.driver.findElement(By.name("debt_pricing_template")).click();

LoginPage2.driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

LoginPage2.driver.switchTo().window("bPageTitle");

请告知需要添加什么?

4

2 回答 2

0

我从未使用过它,因为在我的测试中我没有使用任何新窗口,但这应该会有所帮助:

Set<string> handlers = driver.getWindowHandles();  
 if (driver.getWindowHandles().size()>= 1){  
   for(String handler : handlers){  
    driver.switchTo().window(handler);  
    if (driver.getElement(By.tagName("h1")).contains("Pricing")){  
      System.out.println("Get focus on Popup window");  
      break;  
    }  
   }  
 }  
 else System.out.println("No windows founded!");  

我不太确定 h1 方法。因此,如果它没有帮助,请在打开将当前窗口存储到字符串的新窗口之前尝试:

String mainWindow = driver.getWindowHandle();

然后单击链接(或像现在一样做其他事情)以打开新窗口。然后切换到新窗口:

 Set<string> handlers = driver.getWindowHandles();  
 for (String handler : handlers){
    if (!handler.equals(mainWindow)){
      driver.switchTo(handler);
      break;
    }
 }

然后切换回原始窗口只需执行以下操作:

driver.switchTo(mainWindow);

当然,该driver变量是预期的实时实例 WebDriver

于 2012-12-19T10:59:31.813 回答
-1
driver.findElement(By.linkText("Go to Billing Summary")).click();

driver.findElement(By.linkText("01 Mar 2016")).click();

Thread.sleep(5000);

driver.findElement(By.linkText("AMS TAX")).click();

driver.findElement(By.linkText("00842")).click();

Set<String> instancewindow= driver.getWindowHandles();
    Iterator<String> it = instancewindow.iterator();
    String parent =it.next();
    String child = it.next();
    driver.switchTo().window(child);

driver.switchTo().frame("modalSubWindow");

    driver.findElement(By.linkText("View More Vehicle Details>>")).click();
    driver.switchTo().window(parent);
于 2016-05-16T08:37:16.003 回答