Exemple #1
0
        public void SwitchToWindow(string windowHandle)
        {
            if (IsOpened)
            {
                if (!OpenedWindows.Contains(windowHandle))
                {
                    throw new ArgumentException($"Can`t find window with handle = {windowHandle}");
                }

                DriverKeeper.GetDriver.SwitchTo().Window(windowHandle);
                WindowChanged?.Invoke(windowHandle);
            }
        }
Exemple #2
0
        public void CloseWindow(string windowHandle)
        {
            if (!IsOpened)
            {
                return;
            }
            if (!OpenedWindows.Contains(windowHandle))
            {
                throw new ArgumentException($"Can`t find window with handle = {windowHandle}");
            }
            if (OpenedWindows.Count == 1)
            {
                Quit();
                return;
            }

            string currentHandle = DriverKeeper.GetDriver.CurrentWindowHandle;

            bool windowChanged = false;

            if (currentHandle != windowHandle)
            {
                DriverKeeper.GetDriver.SwitchTo().Window(windowHandle).Close();
                DriverKeeper.GetDriver.SwitchTo().Window(currentHandle);
            }
            else
            {
                DriverKeeper.GetDriver.Close();
                DriverKeeper.GetDriver.SwitchTo().Window(OpenedWindows.Last());
                windowChanged = true;
            }

            WindowClosed?.Invoke(windowHandle);
            if (windowChanged)
            {
                WindowChanged?.Invoke(OpenedWindows.Last());
            }
        }