Пример #1
0
        /// <summary>
        /// Change focus to another window.
        /// </summary>
        /// <param name="title">The name of the window</param>
        /// <param name="timeout"></param>
        public Window SwitchToWindowByTitle(string title, int timeout = -1)
        {
            var endTime = _session.GetEndTime(timeout);

            while (true)
            {
                List windows, handles;
                this.ListWindows(out windows, out handles);
                foreach (Window win in windows)
                {
                    if (win.Handle == _currentWindow.Handle)
                    {
                        continue;
                    }
                    WindowContext.ActivateWindow(_session, win.Handle);
                    string winTitle = GetCurrentTitle(_session);
                    if (winTitle == title)
                    {
                        _previousWindow = _currentWindow;
                        _currentWindow  = win;
                        return(win);
                    }
                }

                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.NoSuchWindowError(title);
                }

                SysWaiter.Wait();
            }
        }
Пример #2
0
        /// <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;
                        }
                    }
                }
            }
        }