Ejemplo n.º 1
0
        /// <summary>
        /// Method for returning a collection of WindowHandles that the driver has access to.
        /// </summary>
        /// <returns>Returns a ReadOnlyCollection of Window Handles.</returns>
        /// <example>
        /// IWebDriver driver = new InternetExplorerDriver();
        /// ReadOnlyCollection<![CDATA[<string>]]> windowNames = driver.GetWindowHandles();
        /// </example>
        public ReadOnlyCollection<string> GetWindowHandles()
        {
            SafeStringCollectionHandle handlesPtr = new SafeStringCollectionHandle();
            WebDriverResult result = NativeDriverLibrary.Instance.GetAllWindowHandles(handle, ref handlesPtr);

            ResultHandler.VerifyResultCode(result, "Unable to obtain all window handles");

            List<string> windowHandleList = new List<string>();
            using (StringCollection windowHandleStringCollection = new StringCollection(handlesPtr))
            {
                windowHandleList = windowHandleStringCollection.ToList();
            }

            return new ReadOnlyCollection<string>(windowHandleList);
        }