는, 내가이 시나리오에 직면 UI 자동화 수행하려고 열려있을 때 하나 windowhandle 카운트 통과 :에, InternetExplorer1에서
을 내 webapp에서 탭의 메뉴를 클릭하면 새로 추가 InternetExplorer2 인스턴스가 URL을로드합니다. 그래서 나는 두 개의 IE를 얻는다. 이제 IE2로 전환하고 거기에서 로그 아웃 버튼을 클릭해야합니다. 이것에 대한 나는 코드가 있습니다driver.WindowHandles 그냥 거기에 인터넷 익스플로러의 두 인스턴스가있어 셀레늄 WebDriver를 사용
[Test]
public void mytest()
{
Assert.IsTrue(IsOpen());
}
public bool IsOpen()
{
GoToUrl();// I pass the URL over here and the element is clicked here
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15));
SwitchWindow();
return true;
}
//Here I switch the window.
private void SwitchWindow()
{
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
var currentWindow = driver.CurrentWindowHandle;
string currentWindowTitle = (string)js.ExecuteScript("return document.title");
var availableWindows = new List<string>(driver.WindowHandles);
foreach (string w in availableWindows)
{
if (w != currentWindow)
{
//This should switch the window.
driver.SwitchTo().Window(w);
//..........................
//.........More of my automation runs here..........
//...........................
}
}
}
을하지만 목록은 WindowHandles에 하나 개의 항목을 통과 availablewindows. 두 개의 인스턴스를 열어두면 안됩니까?
브라우저를로드하고 링크를 클릭하면 코드를 보는 것이 유용 할 수 있습니다. 드라이버 인스턴스가 같다고 가정하면이 코드에 아무런 문제가 보이지 않습니다. 그러나, 그것은 가치가있다 [이] (http://stackoverflow.com/questions/19575095/new-window-handles-disappearing-in-ie-cant-switch-to-new-window) 그래서 그들이 보이는 것 질문 문제가 발생했습니다 (IE 만 해당). – Corporalis