Beispiel #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();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Change focus to another window.
        /// </summary>
        /// <param name="name">The name of the window</param>
        /// <param name="timeout"></param>
        public Window SwitchToWindowByName(string name, int timeout = -1)
        {
            var endTime = _session.GetEndTime(timeout);

            while (true)
            {
                try {
                    string handle = WindowContext.ActivateWindow(_session, name);
                    _previousWindow = _currentWindow;
                    foreach (Window win in _cachedWindows)
                    {
                        if (win.Handle == handle)
                        {
                            _currentWindow = win;
                            return(_currentWindow);
                        }
                    }
                    _currentWindow = new Window(_session, this, null);
                    _cachedWindows.Add(_currentWindow);
                    return(_currentWindow);
                } catch (Errors.NoSuchWindowError) { }

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

                SysWaiter.Wait();
            }
        }