コード例 #1
0
        /// <summary>
        /// Dynamic switching with the help of window handles and element
        /// </summary>
        /// <param name="webActions"></param>
        /// <param name="locater"></param>
        public static void SwitchToWindowWithElement(this WebActions webActions, By locater)
        {
            bool found   = false;
            int  counter = 0;

reAttempt:

            IReadOnlyCollection <string> allHandles = webActions.GetWindowHandles();

            foreach (string handle in allHandles)
            {
                webActions.SwitchToWindow(handle);
                if (webActions.IsElementPresent(locater))
                {
                    found = true;
                    break;
                }
            }

            if (!found && counter < 3)
            {
                goto reAttempt;
            }
        }