2012-08-23 22 views
1

之間切換要登錄到會議爲4個不同的角色,每一個我寫硒的webdriver如何不同的Firefox窗口

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

您創建一個新的FirefoxDriver爲每個角色?如果是這種情況,您應該只使用與每個窗口對應的FirefoxDriver。 –

回答

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

您可以使用此代碼的窗口之間進行切換,如果你願意,你可以根據自己的需要改變它

//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()); 

    } 
相關問題