1

为了以 4 个不同的角色登录会议,对于我写的每个角色

System.setProperty("webdriver.firefox.profile", "default");
FirefoxDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
driver.get("link to the conference");

那么如何在 Firefox 窗口之间切换呢?Windows 标题是相同的。谢谢

4

2 回答 2

1

如果需要,您可以使用此代码在窗口之间导航,您可以根据需要进行更改

//All the window handles will be returned and u can use window handle to switch between the windows

Set<String> windows = getWebDriver().getWindowHandles();

    Iterator<String> window = windows.iterator();


    while( window.hasNext() ) {

        getWebDriver().switchTo().window( window.next() );

    }
于 2012-08-24T12:33:42.633 回答
1
public TasksWindow OpenInWindow() {
    WebDriverWait wait = new WebDriverWait(Driver.driver, TimeSpan.FromSeconds(10));
    wait.IgnoreExceptionTypes(typeof(AssertionException));
    String windowName = wait.Until<String>((d) => {
        this.windowSwitcher.Click();

        if (d.WindowHandles.Count != 2) // this means you are waiting till the number of windows equals 2 {
            return null;
        }

        return d.WindowHandles[1]; // this means you are changing to the second window (from [0] to [1])
    });

    return new TasksWindow(windowName);
}

这适用于c#

于 2012-08-23T23:47:19.160 回答