Exemplo n.º 1
0
 /// <summary>
 ///       Finds the first of elements that match the DOM Tag supplied
 ///       </summary>
 /// <param name="tagName">tag name of the element</param>
 /// <returns>IWebElement object so that you can interact that object</returns>
 /// <example>
 ///   <code>
 ///       IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
 ///       IWebElement elem = driver.FindElementsByTagName("tag")
 ///       </code>
 /// </example>
 public IWebElement FindElementByTagName(string tagName)
 {
     return(DecoratedWebElement.FindElementByTagName(tagName));
 }
Exemplo n.º 2
0
 public new IWebElement FindElementByTagName(string tagName)
 {
     return(WrapElementIfRemote_(webElement_.FindElementByTagName(tagName)));
 }
Exemplo n.º 3
0
        private void BuildPropertiesWithControlType(string webCtrlType = "")
        {
            if (this._webElement == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(webCtrlType))
            {
                webCtrlType = WebKit.generateWebElementType(_webElement);   //get web element's type
            }
            this._webCtrlType = webCtrlType;
            _properties.Add(WebControlKeys.Type, webCtrlType);
            //id
            string webCtrlID = _webElement.GetAttribute("id");

            _properties.Add(WebControlKeys.ID, webCtrlID);
            if (string.IsNullOrEmpty(webCtrlID))
            {
                _recommendedProperties.Add(WebControlKeys.ID, webCtrlID);
            }

            //tag name
            _properties.Add(WebControlKeys.TagName, _webElement.TagName.ToUpper());
            if (string.IsNullOrEmpty(webCtrlID))
            {
                _recommendedProperties.Add(WebControlKeys.TagName, _webElement.TagName.ToUpper());
            }

            //CSS style
            //getComputedStyle

            //CSS class
            string webCtrlClass = _webElement.GetAttribute("class");

            _properties.Add(WebControlKeys.Class, webCtrlClass);
            if (string.IsNullOrEmpty(webCtrlClass))
            {
                _recommendedProperties.Add(WebControlKeys.Class, webCtrlClass);
            }

            //name
            string name = _webElement.GetAttribute("name");

            _properties.Add(WebControlKeys.Name, name);
            if (!string.IsNullOrEmpty(name))
            {
                _recommendedProperties.Add(WebControlKeys.Name, name);
            }

            //BoundingRectangle = WebKit.getScreenRectangle(_webElement);
            Point point = WebUtility.GetElementScreenPos(_webElement);

            BoundingRectangle = new Rectangle(point, _webElement.Size);
            _properties.Add(WebControlKeys.BoundingRectangle, BoundingRectangle.ToString());

            //type
            if (_properties[WebControlKeys.TagName].Equals("INPUT"))
            {
                string attrType = _webElement.GetAttribute("type");
                if (!string.IsNullOrEmpty(attrType))
                {
                    _properties.Add(WebControlKeys.AttrType, attrType);
                    _recommendedProperties.Add(WebControlKeys.AttrType, attrType);
                }
            }

            string ctrlName = string.Empty;

            switch (webCtrlType)
            {
            case "WebPage":
            {
                this._name = /*webCtrlType + " : " +*/ _webElement.WrappedDriver.Title;
                _properties.Add(WebControlKeys.URL, _webElement.WrappedDriver.Url);
                _properties.Add(WebControlKeys.Title, _webElement.WrappedDriver.Title);
            }
            break;

            case "WebFrame":
            {
                string src = WebUtility.GetAttributeWithJavascript(_webElement, "src");
                _properties.Add(WebControlKeys.Src, src);
                if (string.IsNullOrEmpty(name))
                {
                    this._name = /*webCtrlType + " : " +*/ name;
                }
                else
                {
                    this._name = /*webCtrlType + " : " +*/ src;
                }
            }
            break;

            case "WebForm":
            {
                this._name = /*webCtrlType + " : " +*/ name;
            }
            break;

            case "WebTable":
            {
                this._name = /*webCtrlType + " : " +*/ name;
                //        _properties.Add(WebControlKeys.Width, _webElement.Size.Width.ToString());
                //  _properties.Add(WebControlKeys.Height, _webElement.Size.Height.ToString());
            }
            break;

            case "WebLink":
            {
                string Text = _webElement.GetAttribute("textContent");
                _properties.Add(WebControlKeys.Role, _webElement.GetAttribute("role"));
                _properties.Add(WebControlKeys.Text, Text);
                _recommendedProperties.Add(WebControlKeys.Text, Text);
                this._name = /*webCtrlType + " : " +*/ Text;
            }
            break;

            case "WebImage":
            case "WebImageLink":
            {
                string alt = _webElement.GetAttribute("alt");
                string src = WebUtility.GetAttributeWithJavascript(_webElement, "src");        // _webElement.GetAttribute("src");
                _properties.Add(WebControlKeys.Alt, alt);
                _properties.Add(WebControlKeys.Src, src);

                /*if ( src.LastIndexOf('/') >= 0 )
                 * {
                 *  src = src.Substring(src.LastIndexOf('/') + 1);
                 * }*/
                _recommendedProperties.Add(WebControlKeys.Alt, alt);
                this._name = /*_webCtrlType + " : " + */ (string.IsNullOrEmpty(alt) ? src : alt);
            }
            break;

            case "WebButton":
            {
                string name2    = string.Empty;
                string attrType = _webElement.GetAttribute("type");
                switch (_properties[WebControlKeys.TagName])
                {
                case "BUTTON":
                {
                    name2 = _webElement.GetAttribute("textContent");
                    if (string.IsNullOrEmpty(name2))
                    {
                        _properties[WebControlKeys.Name]            = name2;
                        _recommendedProperties[WebControlKeys.Name] = name2;
                        name = name2;
                    }
                }
                break;

                case "INPUT":
                {
                    name = _webElement.GetAttribute("value");
                }
                break;

                default:
                    break;
                }
                this._name = /*_webCtrlType + " : " +*/ name;
            }
            break;

            case "WebEdit":
            {
                this._name = /*_webCtrlType + " : " +*/ name;
            }
            break;

            case "WebList":
            {
                if (string.IsNullOrEmpty(name))
                {
                    RemoteWebElement option = _webElement.FindElementByTagName("option") as RemoteWebElement;
                    name = option.Text;
                }
                this._name = name;
            }
            break;

            case "WebRadioGroup":
            {
                RemoteWebElement parentElement = WebUtility.GetParentElement(_webElement);


                _webElement = (_webElement.WrappedDriver as RemoteWebDriver).FindElementByCssSelector("input[type=radio][name=" + name + "]") as RemoteWebElement;

                if (string.IsNullOrEmpty(name))
                {
                    name = _webElement.GetAttribute("value");
                }

                if (string.IsNullOrEmpty(name))
                {
                    name = _webElement.Text;
                }

                this._name = /*_webCtrlType + " : " +*/ name;
            }
            break;

            case "WebCheckBox":
            {
                ctrlName = _webElement.GetAttribute("aria-label");
                if (!string.IsNullOrEmpty(ctrlName))
                {
                    goto findControlName;
                }

                ctrlName = _webElement.GetAttribute("innerText");
                if (!string.IsNullOrEmpty(ctrlName))
                {
                    goto findControlName;
                }

                RemoteWebElement nextSilbingElement = WebUtility.GetNextSiblingElement(_webElement);

                if (nextSilbingElement != null)
                {
                    if (nextSilbingElement.GetAttribute("nodeType").ToString().Equals("3"))
                    {
                        ctrlName = nextSilbingElement.GetAttribute("textContent");
                        if (!string.IsNullOrEmpty(ctrlName))
                        {
                            goto findControlName;
                        }
                    }
                }


findControlName:
                this._name = /*_webCtrlType + " : " +*/ ctrlName;
            }
            break;

            case "WebElement":
            {
                this._name = string.IsNullOrEmpty(webCtrlID) ? (string.IsNullOrEmpty(name) ? _webElement.TagName.ToUpper() : name) : webCtrlID;
            }
            break;

            default:
                break;
            }
        }