/// <summary> /// Finds a list of elements that match the link text supplied /// </summary> /// <param name="linkText">Link text of element</param> /// <returns>ReadOnlyCollection of IWebElement object so that you can interact with those objects</returns> public ReadOnlyCollection <IWebElement> FindElementsByLinkText(string linkText) { SafeWebElementCollectionHandle collectionHandle = new SafeWebElementCollectionHandle(); WebDriverResult result = NativeDriverLibrary.Instance.FindElementsByLinkText(handle, parent, linkText, ref collectionHandle); ResultHandler.VerifyResultCode(result, "FindElementsByLinkText"); List <IWebElement> elementList = new List <IWebElement>(); using (InternetExplorerWebElementCollection elements = new InternetExplorerWebElementCollection(driver, collectionHandle)) { elementList = elements.ToList(); } return(new ReadOnlyCollection <IWebElement>(elementList)); }
/// <summary> /// Find all the elements taht match the XPath /// </summary> /// <param name="xpath">XPath to the element</param> /// <returns>ReadOnlyCollection of IWebElement object so that you can interact that object</returns> public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath) { SafeWebElementCollectionHandle collectionHandle = new SafeWebElementCollectionHandle(); WebDriverResult result = NativeDriverLibrary.Instance.FindElementsByXPath(handle, parent, xpath, ref collectionHandle); ResultHandler.VerifyResultCode(result, "FindElementsByXPath"); List<IWebElement> elementList = new List<IWebElement>(); using (InternetExplorerWebElementCollection elements = new InternetExplorerWebElementCollection(driver, collectionHandle)) { elementList = elements.ToList(); } return new ReadOnlyCollection<IWebElement>(elementList); }
/// <summary> /// Initializes a new instance of the InternetExplorerWebElementCollection class /// </summary> /// <param name="driver">driver in use</param> /// <param name="elements">Elements on the page</param> public InternetExplorerWebElementCollection(InternetExplorerDriver driver, SafeWebElementCollectionHandle elements) { this.driver = driver; collectionHandle = elements; }
internal static extern WebDriverResult wdcGetElementAtIndex(SafeWebElementCollectionHandle elementCollection, int index, ref SafeInternetExplorerWebElementHandle result);
internal static extern WebDriverResult wdcGetElementCollectionLength(SafeWebElementCollectionHandle elementCollection, ref int count);
internal static extern WebDriverResult wdFindElementsByXPath(SafeInternetExplorerDriverHandle driver, SafeInternetExplorerWebElementHandle element, [MarshalAs(UnmanagedType.LPWStr)] string xpath, ref SafeWebElementCollectionHandle result);
/// <summary> /// Gets the length of an element collection. /// </summary> /// <param name="elementCollectionHandle">A handle to the web element 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 GetElementCollectionLength(SafeWebElementCollectionHandle elementCollectionHandle, ref int count) { IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetElementCollectionLengthFunctionName); GetElementCollectionLengthFunction elementCollectionLengthFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(GetElementCollectionLengthFunction)) as GetElementCollectionLengthFunction; WebDriverResult result = elementCollectionLengthFunction(elementCollectionHandle, ref count); return result; }
/// <summary> /// Gets an item from an element collection. /// </summary> /// <param name="elementCollectionHandle">A handle to the web element collection.</param> /// <param name="index">The index of the item the collection.</param> /// <param name="elementHandle">A handle to the instance of the <see cref="InternetExplorerWebElement"/> class.</param> /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns> internal WebDriverResult GetElementAtIndex(SafeWebElementCollectionHandle elementCollectionHandle, int index, ref SafeInternetExplorerWebElementHandle elementHandle) { IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetElementAtIndexFunctionName); GetElementAtIndexFunction elementCollectionItemFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(GetElementAtIndexFunction)) as GetElementAtIndexFunction; WebDriverResult result = elementCollectionItemFunction(elementCollectionHandle, index, ref elementHandle); return result; }
/// <summary> /// Finds all elements on the page meeting the specified criteria. /// </summary> /// <param name="driverHandle">A handle to the instance of the <see cref="InternetExplorerDriver"/> class.</param> /// <param name="elementHandle">A handle to the instance of the <see cref="InternetExplorerWebElement"/> class.</param> /// <param name="xpath">The criteria to use to find the elements.</param> /// <param name="foundElementCollectionHandle">A handle to the collection containing found elements.</param> /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns> internal WebDriverResult FindElementsByXPath(SafeInternetExplorerDriverHandle driverHandle, SafeInternetExplorerWebElementHandle elementHandle, string xpath, ref SafeWebElementCollectionHandle foundElementCollectionHandle) { IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, FindElementsByXPathFunctionName); ElementCollectionFindingFunction findElementsFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(ElementCollectionFindingFunction)) as ElementCollectionFindingFunction; WebDriverResult result = findElementsFunction(driverHandle, elementHandle, xpath, ref foundElementCollectionHandle); return result; }
/// <summary> /// Find all elements that match the tag /// </summary> /// <param name="tagName">tagName of element on the page</param> /// <returns>ReadOnlyCollection of IWebElement object so that you can interact that object</returns> public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName) { SafeWebElementCollectionHandle collectionHandle = new SafeWebElementCollectionHandle(); WebDriverResult result = NativeMethods.wdFindElementsByTagName(handle, parent, tagName, ref collectionHandle); ResultHandler.VerifyResultCode(result, "FindElementsByTagName"); List<IWebElement> elementList = new List<IWebElement>(); using (InternetExplorerWebElementCollection elements = new InternetExplorerWebElementCollection(driver, collectionHandle)) { elementList = elements.ToList(); } return new ReadOnlyCollection<IWebElement>(elementList); }