Inheritance: Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
        /// <summary>
        /// Converts a Collection of elements into a list
        /// </summary>
        /// <returns>List of IWebElement</returns>
        public List<IWebElement> ToList()
        {
            List<IWebElement> toReturn = new List<IWebElement>();
            int numberOfElements = 0;
            NativeDriverLibrary.Instance.GetElementCollectionLength(collectionHandle, ref numberOfElements);
            for (int i = 0; i < numberOfElements; i++)
            {
                SafeInternetExplorerWebElementHandle wrapper = new SafeInternetExplorerWebElementHandle();
                WebDriverResult result = NativeDriverLibrary.Instance.GetElementAtIndex(collectionHandle, i, ref wrapper);

                // OPTIMIZATION: Check for a success value, then run through the
                // VerifyErrorCode which will throw the proper exception
                if (result != WebDriverResult.Success)
                {
                    try
                    {
                        ResultHandler.VerifyResultCode(result, string.Empty);
                    }
                    catch (Exception e)
                    {
                        // We need to process the exception to free the memory.
                        // Then we can wrap and rethrow.
                        collectionHandle.FreeElementsOnDispose = true;
                        Dispose();
                        throw new WebDriverException("Could not retrieve element " + i + " from element collection", e);
                    }
                }

                toReturn.Add(new InternetExplorerWebElement(driver, wrapper));
            }
            ////TODO(andre.nogueira): from the java code (elementcollection.java)... "Free memory from the collection"
            return toReturn;
        }
        /// <summary>
        /// Converts a Collection of elements into a list
        /// </summary>
        /// <returns>List of IWebElement</returns>
        public List <IWebElement> ToList()
        {
            List <IWebElement> toReturn = new List <IWebElement>();
            int numberOfElements        = 0;

            NativeDriverLibrary.Instance.GetElementCollectionLength(collectionHandle, ref numberOfElements);
            for (int i = 0; i < numberOfElements; i++)
            {
                SafeInternetExplorerWebElementHandle wrapper = new SafeInternetExplorerWebElementHandle();
                WebDriverResult result = NativeDriverLibrary.Instance.GetElementAtIndex(collectionHandle, i, ref wrapper);

                // OPTIMIZATION: Check for a success value, then run through the
                // VerifyErrorCode which will throw the proper exception
                if (result != WebDriverResult.Success)
                {
                    try
                    {
                        ResultHandler.VerifyResultCode(result, string.Empty);
                    }
                    catch (Exception e)
                    {
                        // We need to process the exception to free the memory.
                        // Then we can wrap and rethrow.
                        collectionHandle.FreeElementsOnDispose = true;
                        Dispose();
                        throw new WebDriverException("Could not retrieve element " + i + " from element collection", e);
                    }
                }

                toReturn.Add(new InternetExplorerWebElement(driver, wrapper));
            }
            ////TODO(andre.nogueira): from the java code (elementcollection.java)... "Free memory from the collection"
            return(toReturn);
        }
示例#3
0
 /// <summary>
 /// Find the first element that has this ID
 /// </summary>
 /// <param name="id">ID of web element on the page</param>
 /// <returns>Returns a IWebElement to use</returns>
 public IWebElement FindElementById(string id)
 {
     SafeInternetExplorerWebElementHandle rawElement = new SafeInternetExplorerWebElementHandle();
     WebDriverResult result = NativeDriverLibrary.Instance.FindElementById(handle, parent, id, ref rawElement);
     ResultHandler.VerifyResultCode(result, "FindElementById");
     return new InternetExplorerWebElement(driver, rawElement);
 }
示例#4
0
文件: Finder.cs 项目: epall/selenium
 /// <summary>
 /// Method to return the first element that matches the CSS class passed in
 /// </summary>
 /// <param name="className">CSS class name</param>
 /// <returns>IWebElement object so that you can interact that object</returns>
 public IWebElement FindElementByClassName(string className)
 {
     SafeInternetExplorerWebElementHandle rawElement = new SafeInternetExplorerWebElementHandle();
     WebDriverResult result = NativeMethods.wdFindElementByClassName(handle, parent, className, ref rawElement);
     ResultHandler.VerifyResultCode(result, "FindElementByClassName");
     return new InternetExplorerWebElement(driver, rawElement);
 }
示例#5
0
        /// <summary>
        /// Drag and Drop an element to another element.
        /// </summary>
        /// <param name="element">Element you wish to drop on.</param>
        public void DragAndDropOn(IRenderedWebElement element)
        {
            IntPtr          hwnd   = IntPtr.Zero;
            int             x      = 0;
            int             y      = 0;
            int             width  = 0;
            int             height = 0;
            WebDriverResult result = NativeDriverLibrary.Instance.GetElementDetailsOnceScrolledOnToScreen(elementHandle, ref hwnd, ref x, ref y, ref width, ref height);

            ResultHandler.VerifyResultCode(result, "Unable to determine location once scrolled on to screen");

            int startX = x + (width / 2);
            int startY = y + (height / 2);

            NativeDriverLibrary.Instance.MouseDownAt(hwnd, startX, startY);

            SafeInternetExplorerWebElementHandle other = ((InternetExplorerWebElement)element).Wrapper;

            result = NativeDriverLibrary.Instance.GetElementDetailsOnceScrolledOnToScreen(other, ref hwnd, ref x, ref y, ref width, ref height);
            ResultHandler.VerifyResultCode(result, "Unable to determine location of target once scrolled on to screen");

            int endX = x + (width / 2);
            int endY = y + (height / 2);

            int duration = driver.Manage().Speed.Timeout;

            NativeDriverLibrary.Instance.MouseMoveTo(hwnd, duration, startX, startY, endX, endY);
            NativeDriverLibrary.Instance.MouseUpAt(hwnd, endX, endY);
        }
示例#6
0
        /// <summary>
        /// Method to return the first element that matches the CSS class passed in
        /// </summary>
        /// <param name="className">CSS class name</param>
        /// <returns>IWebElement object so that you can interact that object</returns>
        public IWebElement FindElementByClassName(string className)
        {
            SafeInternetExplorerWebElementHandle rawElement = new SafeInternetExplorerWebElementHandle();
            WebDriverResult result = NativeDriverLibrary.Instance.FindElementByClassName(handle, parent, className, ref rawElement);

            ResultHandler.VerifyResultCode(result, "FindElementByClassName");
            return(new InternetExplorerWebElement(driver, rawElement));
        }
示例#7
0
        /// <summary>
        /// Finds the first of elements that match the link text supplied
        /// </summary>
        /// <param name="linkText">Link text of element </param>
        /// <returns>IWebElement object so that you can interact that object</returns>
        public IWebElement FindElementByLinkText(string linkText)
        {
            SafeInternetExplorerWebElementHandle rawElement = new SafeInternetExplorerWebElementHandle();
            WebDriverResult result = NativeDriverLibrary.Instance.FindElementByLinkText(handle, parent, linkText, ref rawElement);

            ResultHandler.VerifyResultCode(result, "FindElementByLinkText");
            return(new InternetExplorerWebElement(driver, rawElement));
        }
            /// <summary>
            /// Finds the currently active element.
            /// </summary>
            /// <returns>WebElement of the active element.</returns>
            public IWebElement ActiveElement()
            {
                SafeInternetExplorerWebElementHandle rawElement = new SafeInternetExplorerWebElementHandle();
                WebDriverResult result = NativeDriverLibrary.Instance.SwitchToActiveElement(driver.handle, ref rawElement);

                ResultHandler.VerifyResultCode(result, "Unable to find active element");

                return(new InternetExplorerWebElement(driver, rawElement));
            }
示例#9
0
文件: Finder.cs 项目: epall/selenium
        /// <summary>
        /// Initializes a new instance of the Finder class.
        /// </summary>
        /// <param name="driver">InternetExplorerDriver in use</param>
        /// <param name="parent">ElementHandle to for use with the Native methods</param>
        public Finder(InternetExplorerDriver driver, SafeInternetExplorerWebElementHandle parent)
        {
            this.driver = driver;
            if (parent != null)
            {
                this.parent = parent;
            }
            else
            {
                this.parent = new SafeInternetExplorerWebElementHandle();
            }

            handle = driver.GetUnderlayingHandle();
        }
示例#10
0
 internal static extern WebDriverResult wdeSetSelected(SafeInternetExplorerWebElementHandle handle);
示例#11
0
 /// <summary>
 /// Retrieves the value from the script result.
 /// </summary>
 /// <param name="scriptResultHandle">A handle to the result of the script.</param>
 /// <param name="driverHandle">A handle to the instance of the <see cref="InternetExplorerDriver"/> class.</param>
 /// <param name="scriptResultValue">A value representing the value of the returned object from the script.</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult GetElementScriptResult(SafeScriptResultHandle scriptResultHandle, SafeInternetExplorerDriverHandle driverHandle, out SafeInternetExplorerWebElementHandle scriptResultValue)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetElementScriptResultFunctionName);
     ElementReturningScriptResultFunction scriptResultFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(ElementReturningScriptResultFunction)) as ElementReturningScriptResultFunction;
     WebDriverResult result = scriptResultFunction(scriptResultHandle, driverHandle, out scriptResultValue);
     return result;
 }
示例#12
0
 /// <summary>
 /// Gets the size of an element.
 /// </summary>
 /// <param name="elementHandle">A handle to the instance of the <see cref="InternetExplorerWebElement"/> class.</param>
 /// <param name="width">The width of the element.</param>
 /// <param name="height">The height of the element.</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult GetElementSize(SafeInternetExplorerWebElementHandle elementHandle, ref int width, ref int height)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetElementSizeFunctionName);
     CoordinateReturningElementFunction getElementSizeFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(CoordinateReturningElementFunction)) as CoordinateReturningElementFunction;
     WebDriverResult result = getElementSizeFunction(elementHandle, ref width, ref height);
     return result;
 }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the InternetExplorerWebElement class.
 /// </summary>
 /// <param name="driver">Drive in use.</param>
 /// <param name="wrapper">Wrapper of the handle to get.</param>
 internal InternetExplorerWebElement(InternetExplorerDriver driver, SafeInternetExplorerWebElementHandle wrapper)
 {
     this.driver = driver;
     this.elementHandle = wrapper;
 }
示例#14
0
            /// <summary>
            /// Finds the currently active element.
            /// </summary>
            /// <returns>WebElement of the active element.</returns>
            public IWebElement ActiveElement()
            {
                SafeInternetExplorerWebElementHandle rawElement = new SafeInternetExplorerWebElementHandle();
                WebDriverResult result = NativeDriverLibrary.Instance.SwitchToActiveElement(driver.handle, ref rawElement);

                ResultHandler.VerifyResultCode(result, "Unable to find active element");

                return new InternetExplorerWebElement(driver, rawElement);
            }
示例#15
0
 internal static extern WebDriverResult wdeSendKeys(SafeInternetExplorerWebElementHandle wrapper, [MarshalAs(UnmanagedType.LPWStr)] string text);
示例#16
0
 internal static extern WebDriverResult wdeIsDisplayed(SafeInternetExplorerWebElementHandle handle, ref int displayed);
示例#17
0
 internal static extern WebDriverResult wdSwitchToActiveElement(SafeInternetExplorerDriverHandle driver, ref SafeInternetExplorerWebElementHandle result);
示例#18
0
 internal static extern WebDriverResult wdGetElementScriptResult(SafeScriptResultHandle scriptResult, SafeInternetExplorerDriverHandle driver, out SafeInternetExplorerWebElementHandle value);
示例#19
0
 internal static extern WebDriverResult wdAddElementScriptArg(SafeScriptArgsHandle scriptArgs, SafeInternetExplorerWebElementHandle handle);
示例#20
0
 internal static extern WebDriverResult wdFindElementsByXPath(SafeInternetExplorerDriverHandle driver, SafeInternetExplorerWebElementHandle element, [MarshalAs(UnmanagedType.LPWStr)] string xpath, ref SafeWebElementCollectionHandle result);
示例#21
0
 internal static extern WebDriverResult wdFindElementByTagName(SafeInternetExplorerDriverHandle driver, SafeInternetExplorerWebElementHandle element, [MarshalAs(UnmanagedType.LPWStr)] string linkText, ref SafeInternetExplorerWebElementHandle result);
示例#22
0
 internal static extern WebDriverResult wdeToggle(SafeInternetExplorerWebElementHandle handle, ref int toggled);
示例#23
0
 internal static extern WebDriverResult wdeGetText(SafeInternetExplorerWebElementHandle wrapper, ref SafeStringWrapperHandle result);
示例#24
0
 internal static extern WebDriverResult wdeGetValueOfCssProperty(SafeInternetExplorerWebElementHandle handle, [MarshalAs(UnmanagedType.LPWStr)] string attributeName, ref SafeStringWrapperHandle result);
示例#25
0
 internal static extern WebDriverResult wdcGetElementAtIndex(SafeWebElementCollectionHandle elementCollection, int index, ref SafeInternetExplorerWebElementHandle result);
示例#26
0
 internal static extern WebDriverResult wdeIsSelected(SafeInternetExplorerWebElementHandle handle, ref int selected);
示例#27
0
 internal static extern WebDriverResult wdeClear(SafeInternetExplorerWebElementHandle handle);
示例#28
0
 /// <summary>
 /// Gets a value of a CSS property for the element.
 /// </summary>
 /// <param name="elementHandle">A handle to the instance of the <see cref="InternetExplorerWebElement"/> class.</param>
 /// <param name="propertyName">The name of the property.</param>
 /// <param name="propertyValueWrapperHandle">A pointer to a string containing the property value.</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult GetElementValueOfCssProperty(SafeInternetExplorerWebElementHandle elementHandle, string propertyName, ref SafeStringWrapperHandle propertyValueWrapperHandle)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetValueOfCssPropertyFunctionName);
     CssPropertyValueElementFunction getCssPropertyValueFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(CssPropertyValueElementFunction)) as CssPropertyValueElementFunction;
     WebDriverResult result = getCssPropertyValueFunction(elementHandle, propertyName, ref propertyValueWrapperHandle);
     return result;
 }
示例#29
0
 internal static extern WebDriverResult wdeGetAttribute(SafeInternetExplorerDriverHandle driver, SafeInternetExplorerWebElementHandle wrapper, [MarshalAs(UnmanagedType.LPWStr)] string attributeName, ref SafeStringWrapperHandle result);
示例#30
0
 /// <summary>
 /// Gets a text of the element.
 /// </summary>
 /// <param name="elementHandle">A handle to the instance of the <see cref="InternetExplorerWebElement"/> class.</param>
 /// <param name="textWrapperHandle">A pointer to a string containing the text.</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult GetElementText(SafeInternetExplorerWebElementHandle elementHandle, ref SafeStringWrapperHandle textWrapperHandle)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetElementTextFunctionName);
     StringReturningElementFunction getElementTextFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(StringReturningElementFunction)) as StringReturningElementFunction;
     WebDriverResult result = getElementTextFunction(elementHandle, ref textWrapperHandle);
     return result;
 }
示例#31
0
 internal static extern WebDriverResult wdeGetDetailsOnceScrolledOnToScreen(SafeInternetExplorerWebElementHandle element, ref IntPtr hwnd, ref int x, ref int y, ref int width, ref int height);
示例#32
0
 /// <summary>
 /// Initializes a new instance of the Finder class.
 /// </summary>
 /// <param name="driver">InternetExplorerDriver in use</param>
 /// <param name="parent">ElementHandle to for use with the Native methods</param>
 public Finder(InternetExplorerDriver driver, SafeInternetExplorerWebElementHandle parent)
 {
     this.driver = driver;
     this.parent = parent;
     handle = driver.GetUnderlayingHandle();
 }
示例#33
0
 internal static extern WebDriverResult wdeGetLocation(SafeInternetExplorerWebElementHandle element, ref int x, ref int y);
示例#34
0
 /// <summary>
 /// Initializes a new instance of the Finder class.
 /// </summary>
 /// <param name="driver">InternetExplorerDriver in use</param>
 /// <param name="parent">ElementHandle to for use with the Native methods</param>
 public Finder(InternetExplorerDriver driver, SafeInternetExplorerWebElementHandle parent)
 {
     this.driver = driver;
     this.parent = parent;
     handle      = driver.GetUnderlayingHandle();
 }
示例#35
0
 internal static extern WebDriverResult wdeGetSize(SafeInternetExplorerWebElementHandle element, ref int width, ref int height);
示例#36
0
 internal static extern WebDriverResult wdeClick(SafeInternetExplorerWebElementHandle wrapper);
示例#37
0
 /// <summary>
 /// Initializes a new instance of the InternetExplorerWebElement class.
 /// </summary>
 /// <param name="driver">Drive in use.</param>
 /// <param name="wrapper">Wrapper of the handle to get.</param>
 internal InternetExplorerWebElement(InternetExplorerDriver driver, SafeInternetExplorerWebElementHandle wrapper)
 {
     this.driver        = driver;
     this.elementHandle = wrapper;
 }