/// <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)); }
/// <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); }
/// <summary> /// Initializes a new instance of the StringCollection class. /// </summary> /// <param name="elementCollectionHandle">element collection handler</param> public StringCollection(SafeStringCollectionHandle elementCollectionHandle) { handle = elementCollectionHandle; }
internal static extern WebDriverResult wdcGetStringCollectionLength(SafeStringCollectionHandle elementCollection, ref int count);
internal static extern WebDriverResult wdcGetStringAtIndex(SafeStringCollectionHandle elementCollection, int index, ref SafeStringWrapperHandle result);
internal static extern WebDriverResult wdGetAllWindowHandles(SafeInternetExplorerDriverHandle driver, ref SafeStringCollectionHandle handles);
/// <summary> /// Gets all window handles known to this driver. /// </summary> /// <param name="driverHandle">A handle to the instance of the <see cref="InternetExplorerDriver"/> class.</param> /// <param name="windowHandlesCollectionHandle">A pointer to a string collection containing the window handles.</param> /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns> internal WebDriverResult GetAllWindowHandles(SafeInternetExplorerDriverHandle driverHandle, ref SafeStringCollectionHandle windowHandlesCollectionHandle) { IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetAllWindowHandlesFunctionName); StringCollectionReturningDriverFunction getAllWindowHandlesFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(StringCollectionReturningDriverFunction)) as StringCollectionReturningDriverFunction; WebDriverResult result = getAllWindowHandlesFunction(driverHandle, ref windowHandlesCollectionHandle); return result; }
/// <summary> /// Gets the length of a string collection. /// </summary> /// <param name="stringCollectionHandle">A handle to the string collection.</param> /// <param name="count">The number of items in the collection.</param> /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns> internal WebDriverResult GetStringCollectionLength(SafeStringCollectionHandle stringCollectionHandle, ref int count) { IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetStringCollectionLengthFunctionName); GetStringCollectionLengthFunction stringCollectionLengthFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(GetStringCollectionLengthFunction)) as GetStringCollectionLengthFunction; WebDriverResult result = stringCollectionLengthFunction(stringCollectionHandle, ref count); return result; }
/// <summary> /// Gets an item from a string collection. /// </summary> /// <param name="stringCollectionHandle">A handle to the string collection.</param> /// <param name="index">The index of the item the collection.</param> /// <param name="textWrapperHandle">A handle to the retrieved string.</param> /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns> internal WebDriverResult GetStringAtIndex(SafeStringCollectionHandle stringCollectionHandle, int index, ref SafeStringWrapperHandle textWrapperHandle) { IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetStringAtIndexFunctionName); GetStringAtIndexFunction stringCollectionItemFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(GetStringAtIndexFunction)) as GetStringAtIndexFunction; WebDriverResult result = stringCollectionItemFunction(stringCollectionHandle, index, ref textWrapperHandle); return result; }