コード例 #1
0
        /// <summary>
        /// Method to select or unselect element. This operation only applies to input elements such as checkboxes, options in a select and radio buttons.
        /// </summary>
        public void Select()
        {
            WebDriverResult result = NativeDriverLibrary.Instance.SetElementSelected(elementHandle);

            ResultHandler.VerifyResultCode(result, "(Un)selecting element");
        }
コード例 #2
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>
        public void Submit()
        {
            WebDriverResult result = NativeDriverLibrary.Instance.SubmitElement(elementHandle);

            ResultHandler.VerifyResultCode(result, "submit the element");
        }
コード例 #3
0
        /// <summary>
        /// Click this element. If this causes a new page to load, this method will block until the page has loaded. At this point, you should discard all references to this element and any further operations performed on this element
        /// will have undefined behaviour unless you know that the element and the page will still be present. If this element is not clickable, then this operation is a no-op since it's pretty common for someone to accidentally miss
        /// the target when clicking in Real Life.
        /// </summary>
        public void Click()
        {
            WebDriverResult result = NativeDriverLibrary.Instance.ClickElement(elementHandle);

            ResultHandler.VerifyResultCode(result, "click the element");
        }
コード例 #4
0
        /// <summary>
        /// Method for sending native key strokes to the browser.
        /// </summary>
        /// <param name="text">String containing what you would like to type onto the screen.</param>
        public void SendKeys(string text)
        {
            WebDriverResult result = NativeDriverLibrary.Instance.SendKeysToElement(elementHandle, text);

            ResultHandler.VerifyResultCode(result, "send keystrokes to the element");
        }
コード例 #5
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);
        }
コード例 #6
0
            /// <summary>
            /// Refresh the browser.
            /// </summary>
            public void Refresh()
            {
                WebDriverResult result = NativeDriverLibrary.Instance.Refresh(driver.handle);

                ResultHandler.VerifyResultCode(result, "Refreshing page");
            }
コード例 #7
0
            /// <summary>
            /// Move the browser forward.
            /// </summary>
            public void Forward()
            {
                WebDriverResult result = NativeDriverLibrary.Instance.GoForward(driver.handle);

                ResultHandler.VerifyResultCode(result, "Going forward in history");
            }
コード例 #8
0
            /// <summary>
            /// Move the browser back.
            /// </summary>
            public void Back()
            {
                WebDriverResult result = NativeDriverLibrary.Instance.GoBack(driver.handle);

                ResultHandler.VerifyResultCode(result, "Going back in history");
            }