/// <summary> /// Switch to the next available window /// </summary> /// <param name="timeout"></param> /// <returns></returns> public Window SwitchToNextWindow(int timeout = -1) { DateTime endTime = _session.GetEndTime(timeout); string currentHandle = _currentWindow.Handle; string previousHandle = _previousWindow.Handle; while (true) { List windows, handles; this.ListWindows(out windows, out handles); int count = handles.Count; if (count > 1) // need more than one window //search index of the current windows { int i = count; while (i-- > 0 && (string)handles[i] != currentHandle) { ; } //search and activate the next window for (int ii = count; ii-- > 0;) { if (++i == count) { i = 0; } var handle = (string)handles[i]; if (handle != currentHandle && handle != previousHandle) { return(ActivateWindow((Window)windows[i])); } } } //handle time out if (DateTime.UtcNow > endTime) { throw new Errors.NoSuchWindowError(); } SysWaiter.Wait(); handles = (List)_session.SendAgain(); } }
/// <summary> /// Switches focus to the specified frame, by index, name or WebElement. /// </summary> /// <param name="identifier">The name, id, or WebElement of the frame to switch.</param> /// <param name="timeout">Optional timeout in milliseconds</param> public void SwitchToFrame(object identifier, int timeout) { if (identifier == null) { throw new Errors.ArgumentError("Invalid type for argument identifier"); } var element = identifier as WebElement; if (element != null) { identifier = element.SerializeJson(); } try { _session.Send(RequestMethod.POST, "/frame", "id", identifier); } catch (Errors.NoSuchFrameError) { if (timeout == 0) { throw; } var endTime = _session.GetEndTime(timeout); while (true) { SysWaiter.Wait(); try { _session.SendAgain(); break; } catch (Errors.NoSuchFrameError) { if (DateTime.UtcNow > endTime) { throw; } } } } }