为了以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标题是相同的。 感谢
答案 0 :(得分: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#
答案 1 :(得分: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() );
}