Inheritance: Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
コード例 #1
0
            /// <summary>
            /// Method for getting a Collection of Cookies that are present in the browser.
            /// </summary>
            /// <returns>ReadOnlyCollection of Cookies in the browser.</returns>
            public ReadOnlyCollection <Cookie> GetCookies()
            {
                Uri currentUri = GetCurrentUri();

                SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
                WebDriverResult         result       = NativeDriverLibrary.Instance.GetCookies(driver.handle, ref stringHandle);

                ResultHandler.VerifyResultCode(result, "Getting Cookies");
                string allDomainCookies = string.Empty;

                using (StringWrapper wrapper = new StringWrapper(stringHandle))
                {
                    allDomainCookies = wrapper.Value;
                }

                List <Cookie> toReturn = new List <Cookie>();

                string[] cookies = allDomainCookies.Split(new string[] { "; " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string cookie in cookies)
                {
                    string[] parts = cookie.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length != 2)
                    {
                        continue;
                    }

                    toReturn.Add(new ReturnedCookie(parts[0], parts[1], currentUri.Host, string.Empty, null, false, currentUri));
                }

                return(new ReadOnlyCollection <Cookie>(toReturn));
            }
コード例 #2
0
ファイル: StringCollection.cs プロジェクト: hugs/selenium
        /// <summary>
        /// Converts the Collection to a list
        /// </summary>
        /// <returns>A list of strings </returns>
        public List<string> ToList()
        {
            int elementCount = 0;
            WebDriverResult result = NativeDriverLibrary.Instance.GetStringCollectionLength(handle, ref elementCount);
            if (result != WebDriverResult.Success)
            {
                Dispose();
                throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Cannot extract strings from collection: {0}", result));
            }

            List<string> toReturn = new List<string>();
            for (int i = 0; i < elementCount; i++)
            {
                SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
                result = NativeDriverLibrary.Instance.GetStringAtIndex(handle, i, ref stringHandle);
                if (result != WebDriverResult.Success)
                {
                    stringHandle.Dispose();
                    Dispose();
                    throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Cannot extract string from collection at index: {0} ({1})", i, result));
                }

                using (StringWrapper wrapper = new StringWrapper(stringHandle))
                {
                    toReturn.Add(wrapper.Value);
                }
            }

            // TODO(andre.nogueira): from the java code (elementcollection.java)... "Free memory from the collection"
            // Dispose();
            return toReturn;
        }
コード例 #3
0
        /// <summary>
        /// Converts the Collection to a list
        /// </summary>
        /// <returns>A list of strings </returns>
        public List <string> ToList()
        {
            int             elementCount = 0;
            WebDriverResult result       = NativeDriverLibrary.Instance.GetStringCollectionLength(handle, ref elementCount);

            if (result != WebDriverResult.Success)
            {
                Dispose();
                throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Cannot extract strings from collection: {0}", result));
            }

            List <string> toReturn = new List <string>();

            for (int i = 0; i < elementCount; i++)
            {
                SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
                result = NativeDriverLibrary.Instance.GetStringAtIndex(handle, i, ref stringHandle);
                if (result != WebDriverResult.Success)
                {
                    stringHandle.Dispose();
                    Dispose();
                    throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Cannot extract string from collection at index: {0} ({1})", i, result));
                }

                using (StringWrapper wrapper = new StringWrapper(stringHandle))
                {
                    toReturn.Add(wrapper.Value);
                }
            }

            // TODO(andre.nogueira): from the java code (elementcollection.java)... "Free memory from the collection"
            // Dispose();
            return(toReturn);
        }
コード例 #4
0
        /// <summary>
        /// Method to return the value of a CSS Property
        /// </summary>
        /// <param name="propertyName">CSS property key</param>
        /// <returns>string value of the CSS property</returns>
        public string GetValueOfCssProperty(string propertyName)
        {
            SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
            WebDriverResult         result       = NativeDriverLibrary.Instance.GetElementValueOfCssProperty(elementHandle, propertyName, ref stringHandle);

            ResultHandler.VerifyResultCode(result, string.Format(CultureInfo.InvariantCulture, "get the value of CSS property '{0}'", propertyName));
            string returnValue = string.Empty;

            using (StringWrapper wrapper = new StringWrapper(stringHandle))
            {
                returnValue = wrapper.Value;
            }

            return(returnValue);
        }
コード例 #5
0
        /// <summary>
        /// Returns the Name of Window that the driver is working in.
        /// </summary>
        /// <returns>Returns the name of the Window.</returns>
        /// <example>
        /// IWebDriver driver = new InternetExplorerDriver();
        /// string windowName = driver.GetWindowHandles();
        /// </example>
        public string GetWindowHandle()
        {
            SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
            WebDriverResult         result       = NativeDriverLibrary.Instance.GetCurrentWindowHandle(handle, ref stringHandle);

            ResultHandler.VerifyResultCode(result, "Unable to obtain current window handle");
            string handleValue = string.Empty;

            using (StringWrapper wrapper = new StringWrapper(stringHandle))
            {
                handleValue = wrapper.Value;
            }

            return(handleValue);
        }
コード例 #6
0
        /// <summary>
        /// If this current element is a form, or an element within a form, then this will be submitted to the remote server. If this causes the current page to change, then this method will block until the new page is loaded.
        /// </summary>
        /// <param name="attributeName">Attribute you wish to get details of.</param>
        /// <returns>The attribute's current value or null if the value is not set.</returns>
        public string GetAttribute(string attributeName)
        {
            SafeStringWrapperHandle          stringHandle = new SafeStringWrapperHandle();
            SafeInternetExplorerDriverHandle driverHandle = driver.GetUnderlayingHandle();
            WebDriverResult result = NativeDriverLibrary.Instance.GetElementAttribute(driverHandle, elementHandle, attributeName, ref stringHandle);

            ResultHandler.VerifyResultCode(result, string.Format(CultureInfo.InvariantCulture, "getting attribute '{0}' of the element", attributeName));
            string returnValue = null;

            using (StringWrapper wrapper = new StringWrapper(stringHandle))
            {
                returnValue = wrapper.Value;
            }

            return(returnValue);
        }
コード例 #7
0
        /// <summary>
        /// Gets a <see cref="Screenshot"/> object representing the image of the page on the screen.
        /// </summary>
        /// <returns>A <see cref="Screenshot"/> object containing the image.</returns>
        public Screenshot GetScreenshot()
        {
            Screenshot currentScreenshot         = null;
            SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
            WebDriverResult         result       = NativeDriverLibrary.Instance.CaptureScreenshotAsBase64(handle, ref stringHandle);

            ResultHandler.VerifyResultCode(result, "Unable to get screenshot");
            string screenshotValue = string.Empty;

            using (StringWrapper wrapper = new StringWrapper(stringHandle))
            {
                screenshotValue = wrapper.Value;
            }

            if (!string.IsNullOrEmpty(screenshotValue))
            {
                currentScreenshot = new Screenshot(screenshotValue);
            }

            return(currentScreenshot);
        }
コード例 #8
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdCaptureScreenshotAsBase64(SafeInternetExplorerDriverHandle driver, out SafeStringWrapperHandle handle);
コード例 #9
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdGetTitle(SafeInternetExplorerDriverHandle handle, ref SafeStringWrapperHandle result);
コード例 #10
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdStringLength(SafeStringWrapperHandle handle, ref int length);
コード例 #11
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <summary>
 /// Retrieves the value from the script result.
 /// </summary>
 /// <param name="scriptResultHandle">A handle to the result of the script.</param>
 /// <param name="scriptResultValueWrapperHandle">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 GetStringScriptResult(SafeScriptResultHandle scriptResultHandle, ref SafeStringWrapperHandle scriptResultValueWrapperHandle)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetStringScriptResultFunctionName);
     StringReturningScriptResultFunction scriptResultFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(StringReturningScriptResultFunction)) as StringReturningScriptResultFunction;
     WebDriverResult result = scriptResultFunction(scriptResultHandle, ref scriptResultValueWrapperHandle);
     return result;
 }
コード例 #12
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdGetStringScriptResult(SafeScriptResultHandle scriptResult, ref SafeStringWrapperHandle resultString);
コード例 #13
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <summary>
 /// Gets a screenshot of the browser window as a base64 encoded string.
 /// </summary>
 /// <param name="driverHandle">A handle to the instance of the <see cref="InternetExplorerDriver"/> class.</param>
 /// <param name="screenshotWrapperHandle">A pointer to a string containing the screenshot.</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult CaptureScreenshotAsBase64(SafeInternetExplorerDriverHandle driverHandle, ref SafeStringWrapperHandle screenshotWrapperHandle)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, CaptureScreenshotFunctionName);
     StringReturningDriverFunction captureScreenshotFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(StringReturningDriverFunction)) as StringReturningDriverFunction;
     WebDriverResult result = captureScreenshotFunction(driverHandle, ref screenshotWrapperHandle);
     return result;
 }
コード例 #14
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <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;
 }
コード例 #15
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdeGetAttribute(SafeInternetExplorerDriverHandle driver, SafeInternetExplorerWebElementHandle wrapper, [MarshalAs(UnmanagedType.LPWStr)] string attributeName, ref SafeStringWrapperHandle result);
コード例 #16
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdeGetValueOfCssProperty(SafeInternetExplorerWebElementHandle handle, [MarshalAs(UnmanagedType.LPWStr)] string attributeName, ref SafeStringWrapperHandle result);
コード例 #17
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <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;
 }
コード例 #18
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <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;
 }
コード例 #19
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <summary>
 /// Gets an attribute of the specified element.
 /// </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="attributeName">The name of the attribute.</param>
 /// <param name="attributeValueWrapperHandle">A pointer to a string containing the attribute value.</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult GetElementAttribute(SafeInternetExplorerDriverHandle driverHandle, SafeInternetExplorerWebElementHandle elementHandle, string attributeName, ref SafeStringWrapperHandle attributeValueWrapperHandle)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetElementAttributeFunctionName);
     GetElementAttributeFunction getAttributeFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(GetElementAttributeFunction)) as GetElementAttributeFunction;
     WebDriverResult result = getAttributeFunction(driverHandle, elementHandle, attributeName, ref attributeValueWrapperHandle);
     return result;
 }
コード例 #20
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <summary>
 /// Gets the identifying handle string of the current window.
 /// </summary>
 /// <param name="driverHandle">A handle to the instance of the <see cref="InternetExplorerDriver"/> class.</param>
 /// <param name="handleWrapperHandle">A pointer to a string containing the window .</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult GetCurrentWindowHandle(SafeInternetExplorerDriverHandle driverHandle, ref SafeStringWrapperHandle handleWrapperHandle)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, GetCurrentWindowHandleFunctionName);
     StringReturningDriverFunction getCurrentWindowHandleFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(StringReturningDriverFunction)) as StringReturningDriverFunction;
     WebDriverResult result = getCurrentWindowHandleFunction(driverHandle, ref handleWrapperHandle);
     return result;
 }
コード例 #21
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <summary>
 /// Copies a string.
 /// </summary>
 /// <param name="stringWrapperHandle">A pointer to the string to copy.</param>
 /// <param name="length">The length of the string to copy.</param>
 /// <param name="copiedString">The copied string.</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult CopyString(SafeStringWrapperHandle stringWrapperHandle, int length, StringBuilder copiedString)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, CopyStringFunctionName);
     CopyStringFunction copyFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(CopyStringFunction)) as CopyStringFunction;
     WebDriverResult result = copyFunction(stringWrapperHandle, length, copiedString);
     return result;
 }
コード例 #22
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdcGetStringAtIndex(SafeStringCollectionHandle elementCollection, int index, ref SafeStringWrapperHandle result);
コード例 #23
0
        /// <summary>
        /// Gets a <see cref="Screenshot"/> object representing the image of the page on the screen.
        /// </summary>
        /// <returns>A <see cref="Screenshot"/> object containing the image.</returns>
        public Screenshot GetScreenshot()
        {
            Screenshot currentScreenshot = null;
            SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
            WebDriverResult result = NativeDriverLibrary.Instance.CaptureScreenshotAsBase64(handle, ref stringHandle);
            ResultHandler.VerifyResultCode(result, "Unable to get screenshot");
            string screenshotValue = string.Empty;
            using (StringWrapper wrapper = new StringWrapper(stringHandle))
            {
                screenshotValue = wrapper.Value;
            }

            if (!string.IsNullOrEmpty(screenshotValue))
            {
                currentScreenshot = new Screenshot(screenshotValue);
            }

            return currentScreenshot;
        }
コード例 #24
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdCopyString(SafeStringWrapperHandle handle, int length, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder res);
コード例 #25
0
ファイル: NativeDriverLibrary.cs プロジェクト: hugs/selenium
 /// <summary>
 /// Gets the length of a string.
 /// </summary>
 /// <param name="stringWrapperHandle">A pointer to the string to get the length of.</param>
 /// <param name="length">The length of the string.</param>
 /// <returns>A <see cref="WebDriverResult"/> value indicating success or failure.</returns>
 internal WebDriverResult StringLength(SafeStringWrapperHandle stringWrapperHandle, ref int length)
 {
     IntPtr functionPointer = NativeMethods.GetProcAddress(nativeLibraryHandle, StringLengthFunctionName);
     StringLengthFunction getStringLengthFunction = Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(StringLengthFunction)) as StringLengthFunction;
     WebDriverResult result = getStringLengthFunction(stringWrapperHandle, ref length);
     return result;
 }
コード例 #26
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdeGetText(SafeInternetExplorerWebElementHandle wrapper, ref SafeStringWrapperHandle result);
コード例 #27
0
        private object ExtractReturnValue(SafeScriptResultHandle scriptResult)
        {
            WebDriverResult result;

            int type;
            result = NativeDriverLibrary.Instance.GetScriptResultType(handle, scriptResult, out type);

            ResultHandler.VerifyResultCode(result, "Cannot determine result type");

            object toReturn = null;
            try
            {
                switch (type)
                {
                    case 1:
                        SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
                        result = NativeDriverLibrary.Instance.GetStringScriptResult(scriptResult, ref stringHandle);
                        ResultHandler.VerifyResultCode(result, "Cannot extract string result");
                        using (StringWrapper wrapper = new StringWrapper(stringHandle))
                        {
                            toReturn = wrapper.Value;
                        }

                        break;

                    case 2:
                        long longVal;
                        result = NativeDriverLibrary.Instance.GetNumberScriptResult(scriptResult, out longVal);
                        ResultHandler.VerifyResultCode(result, "Cannot extract number result");
                        toReturn = longVal;
                        break;

                    case 3:
                        int boolVal;
                        result = NativeDriverLibrary.Instance.GetBooleanScriptResult(scriptResult, out boolVal);
                        ResultHandler.VerifyResultCode(result, "Cannot extract boolean result");
                        toReturn = boolVal == 1 ? true : false;
                        break;

                    case 4:
                        SafeInternetExplorerWebElementHandle element;
                        result = NativeDriverLibrary.Instance.GetElementScriptResult(scriptResult, handle, out element);
                        ResultHandler.VerifyResultCode(result, "Cannot extract element result");
                        toReturn = new InternetExplorerWebElement(this, element);
                        break;

                    case 5:
                        toReturn = null;
                        break;

                    case 6:
                        SafeStringWrapperHandle messageHandle = new SafeStringWrapperHandle();
                        result = NativeDriverLibrary.Instance.GetStringScriptResult(scriptResult, ref messageHandle);
                        ResultHandler.VerifyResultCode(result, "Cannot extract string result");
                        string message = string.Empty;
                        using (StringWrapper wrapper = new StringWrapper(messageHandle))
                        {
                            message = wrapper.Value;
                        }

                        throw new WebDriverException(message);

                    case 7:
                        double doubleVal;
                        result = NativeDriverLibrary.Instance.GetDoubleScriptResult(scriptResult, out doubleVal);
                        ResultHandler.VerifyResultCode(result, "Cannot extract number result");
                        toReturn = doubleVal;
                        break;

                    case 8:
                        bool allArrayItemsAreElements = true;
                        int arrayLength = 0;
                        result = NativeDriverLibrary.Instance.GetArrayLengthScriptResult(handle, scriptResult, out arrayLength);
                        ResultHandler.VerifyResultCode(result, "Cannot extract array length.");
                        List<object> list = new List<object>();
                        for (int i = 0; i < arrayLength; i++)
                        {
                            // Get reference to object
                            SafeScriptResultHandle currItemHandle = new SafeScriptResultHandle();
                            WebDriverResult getItemResult = NativeDriverLibrary.Instance.GetArrayItemFromScriptResult(handle, scriptResult, i, out currItemHandle);
                            if (getItemResult != WebDriverResult.Success)
                            {
                                // Note about memory management: Usually memory for this item
                                // will be released during the recursive call to
                                // ExtractReturnValue. It is freed explicitly here since a
                                // recursive call will not happen.
                                currItemHandle.Dispose();
                                throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Cannot extract element from collection at index: {0} ({1})", i, result));
                            }

                            object arrayItem = ExtractReturnValue(currItemHandle);
                            if (allArrayItemsAreElements && !(arrayItem is IWebElement))
                            {
                                allArrayItemsAreElements = false;
                            }

                            // Call ExtractReturnValue with the fetched item (recursive)
                            list.Add(arrayItem);
                        }

                        if (allArrayItemsAreElements)
                        {
                            List<IWebElement> elementList = new List<IWebElement>();
                            foreach (object item in list)
                            {
                                elementList.Add((IWebElement)item);
                            }

                            toReturn = elementList.AsReadOnly();
                        }
                        else
                        {
                            toReturn = list.AsReadOnly();
                        }

                        break;

                    default:
                        throw new WebDriverException("Cannot determine result type");
                }
            }
            finally
            {
                scriptResult.Dispose();
            }

            return toReturn;
        }
コード例 #28
0
ファイル: StringWrapper.cs プロジェクト: greghicks01/selenium
 /// <summary>
 /// Initializes a new instance of the StringWrapper class
 /// </summary>
 /// <param name="stringHandle">Instance of the <see cref="SafeStringWrapperHandle"/></param>
 internal StringWrapper(SafeStringWrapperHandle stringHandle)
 {
     handle = stringHandle;
 }
コード例 #29
0
        /// <summary>
        /// Method to return the value of a CSS Property
        /// </summary>
        /// <param name="propertyName">CSS property key</param>
        /// <returns>string value of the CSS property</returns>
        public string GetValueOfCssProperty(string propertyName)
        {
            SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
            WebDriverResult result = NativeDriverLibrary.Instance.GetElementValueOfCssProperty(elementHandle, propertyName, ref stringHandle);
            ResultHandler.VerifyResultCode(result, string.Format(CultureInfo.InvariantCulture, "get the value of CSS property '{0}'", propertyName));
            string returnValue = string.Empty;
            using (StringWrapper wrapper = new StringWrapper(stringHandle))
            {
                returnValue = wrapper.Value;
            }

            return returnValue;
        }
コード例 #30
0
        /// <summary>
        /// Returns the Name of Window that the driver is working in.
        /// </summary>
        /// <returns>Returns the name of the Window.</returns>
        /// <example>
        /// IWebDriver driver = new InternetExplorerDriver();
        /// string windowName = driver.GetWindowHandles();
        /// </example>
        public string GetWindowHandle()
        {
            SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
            WebDriverResult result = NativeDriverLibrary.Instance.GetCurrentWindowHandle(handle, ref stringHandle);
            ResultHandler.VerifyResultCode(result, "Unable to obtain current window handle");
            string handleValue = string.Empty;
            using (StringWrapper wrapper = new StringWrapper(stringHandle))
            {
                handleValue = wrapper.Value;
            }

            return handleValue;
        }
コード例 #31
0
        private object ExtractReturnValue(SafeScriptResultHandle scriptResult)
        {
            WebDriverResult result;

            int type;

            result = NativeDriverLibrary.Instance.GetScriptResultType(handle, scriptResult, out type);

            ResultHandler.VerifyResultCode(result, "Cannot determine result type");

            object toReturn = null;

            try
            {
                switch (type)
                {
                case 1:
                    SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
                    result = NativeDriverLibrary.Instance.GetStringScriptResult(scriptResult, ref stringHandle);
                    ResultHandler.VerifyResultCode(result, "Cannot extract string result");
                    using (StringWrapper wrapper = new StringWrapper(stringHandle))
                    {
                        toReturn = wrapper.Value;
                    }

                    break;

                case 2:
                    long longVal;
                    result = NativeDriverLibrary.Instance.GetNumberScriptResult(scriptResult, out longVal);
                    ResultHandler.VerifyResultCode(result, "Cannot extract number result");
                    toReturn = longVal;
                    break;

                case 3:
                    int boolVal;
                    result = NativeDriverLibrary.Instance.GetBooleanScriptResult(scriptResult, out boolVal);
                    ResultHandler.VerifyResultCode(result, "Cannot extract boolean result");
                    toReturn = boolVal == 1 ? true : false;
                    break;

                case 4:
                    SafeInternetExplorerWebElementHandle element;
                    result = NativeDriverLibrary.Instance.GetElementScriptResult(scriptResult, handle, out element);
                    ResultHandler.VerifyResultCode(result, "Cannot extract element result");
                    toReturn = new InternetExplorerWebElement(this, element);
                    break;

                case 5:
                    toReturn = null;
                    break;

                case 6:
                    SafeStringWrapperHandle messageHandle = new SafeStringWrapperHandle();
                    result = NativeDriverLibrary.Instance.GetStringScriptResult(scriptResult, ref messageHandle);
                    ResultHandler.VerifyResultCode(result, "Cannot extract string result");
                    string message = string.Empty;
                    using (StringWrapper wrapper = new StringWrapper(messageHandle))
                    {
                        message = wrapper.Value;
                    }

                    throw new WebDriverException(message);

                case 7:
                    double doubleVal;
                    result = NativeDriverLibrary.Instance.GetDoubleScriptResult(scriptResult, out doubleVal);
                    ResultHandler.VerifyResultCode(result, "Cannot extract number result");
                    toReturn = doubleVal;
                    break;

                case 8:
                    bool allArrayItemsAreElements = true;
                    int  arrayLength = 0;
                    result = NativeDriverLibrary.Instance.GetArrayLengthScriptResult(handle, scriptResult, out arrayLength);
                    ResultHandler.VerifyResultCode(result, "Cannot extract array length.");
                    List <object> list = new List <object>();
                    for (int i = 0; i < arrayLength; i++)
                    {
                        // Get reference to object
                        SafeScriptResultHandle currItemHandle = new SafeScriptResultHandle();
                        WebDriverResult        getItemResult  = NativeDriverLibrary.Instance.GetArrayItemFromScriptResult(handle, scriptResult, i, out currItemHandle);
                        if (getItemResult != WebDriverResult.Success)
                        {
                            // Note about memory management: Usually memory for this item
                            // will be released during the recursive call to
                            // ExtractReturnValue. It is freed explicitly here since a
                            // recursive call will not happen.
                            currItemHandle.Dispose();
                            throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Cannot extract element from collection at index: {0} ({1})", i, result));
                        }

                        object arrayItem = ExtractReturnValue(currItemHandle);
                        if (allArrayItemsAreElements && !(arrayItem is IWebElement))
                        {
                            allArrayItemsAreElements = false;
                        }

                        // Call ExtractReturnValue with the fetched item (recursive)
                        list.Add(arrayItem);
                    }

                    if (allArrayItemsAreElements)
                    {
                        List <IWebElement> elementList = new List <IWebElement>();
                        foreach (object item in list)
                        {
                            elementList.Add((IWebElement)item);
                        }

                        toReturn = elementList.AsReadOnly();
                    }
                    else
                    {
                        toReturn = list.AsReadOnly();
                    }

                    break;

                default:
                    throw new WebDriverException("Cannot determine result type");
                }
            }
            finally
            {
                scriptResult.Dispose();
            }

            return(toReturn);
        }
コード例 #32
0
            /// <summary>
            /// Method for getting a Collection of Cookies that are present in the browser.
            /// </summary>
            /// <returns>ReadOnlyCollection of Cookies in the browser.</returns>
            public ReadOnlyCollection<Cookie> GetCookies()
            {
                Uri currentUri = GetCurrentUri();

                SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
                WebDriverResult result = NativeDriverLibrary.Instance.GetCookies(driver.handle, ref stringHandle);
                ResultHandler.VerifyResultCode(result, "Getting Cookies");
                string allDomainCookies = string.Empty;
                using (StringWrapper wrapper = new StringWrapper(stringHandle))
                {
                    allDomainCookies = wrapper.Value;
                }

                List<Cookie> toReturn = new List<Cookie>();

                string[] cookies = allDomainCookies.Split(new string[] { "; " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string cookie in cookies)
                {
                    string[] parts = cookie.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length != 2)
                    {
                        continue;
                    }

                    toReturn.Add(new ReturnedCookie(parts[0], parts[1], currentUri.Host, string.Empty, null, false, currentUri));
                }

                return new ReadOnlyCollection<Cookie>(toReturn);
            }
コード例 #33
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdGetCookies(SafeInternetExplorerDriverHandle handle, ref SafeStringWrapperHandle cookies);
コード例 #34
0
        /// <summary>
        /// If this current element is a form, or an element within a form, then this will be submitted to the remote server. If this causes the current page to change, then this method will block until the new page is loaded.
        /// </summary>
        /// <param name="attributeName">Attribute you wish to get details of.</param>
        /// <returns>The attribute's current value or null if the value is not set.</returns>
        public string GetAttribute(string attributeName)
        {
            SafeStringWrapperHandle stringHandle = new SafeStringWrapperHandle();
            SafeInternetExplorerDriverHandle driverHandle = driver.GetUnderlayingHandle();
            WebDriverResult result = NativeDriverLibrary.Instance.GetElementAttribute(driverHandle, elementHandle, attributeName, ref stringHandle);
            ResultHandler.VerifyResultCode(result, string.Format(CultureInfo.InvariantCulture, "getting attribute '{0}' of the element", attributeName));
            string returnValue = null;
            using (StringWrapper wrapper = new StringWrapper(stringHandle))
            {
                returnValue = wrapper.Value;
            }

            return returnValue;
        }
コード例 #35
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdGetCurrentWindowHandle(SafeInternetExplorerDriverHandle driver, out SafeStringWrapperHandle handle);
コード例 #36
0
 /// <summary>
 /// Initializes a new instance of the StringWrapper class
 /// </summary>
 /// <param name="stringHandle">Instance of the <see cref="SafeStringWrapperHandle"/></param>
 internal StringWrapper(SafeStringWrapperHandle stringHandle)
 {
     handle = stringHandle;
 }
コード例 #37
0
ファイル: NativeMethods.cs プロジェクト: epall/selenium
 internal static extern WebDriverResult wdGetPageSource(SafeInternetExplorerDriverHandle driver, ref SafeStringWrapperHandle wrapper);