private static bool isElementContentEditable(RemoteWebElement webElement) { while (null != webElement) { string Editable = webElement.GetAttribute("contentEditable"); if (webElement.GetAttribute("nodeType") != "1" || Editable.Equals("inherit") || Editable.Equals("false")) { webElement = WebUtility.GetParentElement(webElement); continue; } return(!Editable.Equals("false")); } return(false); }
private static bool isRealLink(RemoteWebElement webElement) { if (webElement == null) { return(false); } string href = webElement.GetAttribute("href"); if (string.IsNullOrEmpty(href)) { return(false); } return(true); }
public virtual string GetRoProperty(string propertyname) { RemoteWebElement webElement = RelayObject.SEWebElement; propertyname = propertyname.ToLower(); string returnValue = string.Empty; switch (propertyname) { case "x": { returnValue = webElement.Location.X.ToString(); } break; case "y": { returnValue = webElement.Location.Y.ToString(); } break; case "tagName": { returnValue = webElement.TagName; } break; case "width": { returnValue = webElement.Size.Width.ToString(); } break; case "height": { returnValue = webElement.Size.Height.ToString(); } break; default: { returnValue = webElement.GetAttribute(propertyname); } break; } return(returnValue); }
public virtual void DragAndDrop(IWebElement target) { ActionsHelper actionsHelper = ActionsHelper.getInstance(); RemoteWebElement webElement = RelayObject.SEWebElement; string draggable = webElement.GetAttribute("draggable"); if (!string.IsNullOrEmpty(draggable) && draggable.ToLower().Equals("true")) { BrowserHoster.getInstance().WebDriver.ExecuteScript(_jsDnD, RelayObject.SEWebElement, target.RelayObject.SEWebElement); } else { actionsHelper.DragAndDrop(RelayObject.SEWebElement, target.RelayObject.SEWebElement); } }
public void AssertThat_QuickNavigationHyperlink_ScrollsPageTo_ProperSection(IWebElement navigationHyperlink) { RemoteWebElement hyperlink = (RemoteWebElement)navigationHyperlink; this.ScrollQuickNavigationHyperlink(hyperlink); string navigationHyperlinkHref = hyperlink.GetAttribute("href"); string sectionID = navigationHyperlinkHref.Substring(navigationHyperlinkHref.IndexOf('#') + 1); IWebElement articleSection = this.ArticleSection(sectionID); RemoteWebElement section = (RemoteWebElement)articleSection; this.mouseActions.PressElement(hyperlink); this.ScrollQuickNavigationHyperlink(hyperlink); Assert.That(section.Displayed); Assert.AreEqual(hyperlink.Text, section.Text); }
public void AssertThat_QuickNavigationHyperlinks_ScrollPageTo_ProperSections() { foreach (IWebElement navigationHyperlink in this.QuickNavigationHyperlinks) { RemoteWebElement hyperlink = (RemoteWebElement)navigationHyperlink; this.ScrollQuickNavigationHyperlink(hyperlink); string navigationHyperlinkHref = hyperlink.GetAttribute("href"); string sectionID = navigationHyperlinkHref.Substring(navigationHyperlinkHref.IndexOf('#') + 1); IWebElement articleSection = this.ArticleSection(sectionID); RemoteWebElement section = (RemoteWebElement)articleSection; hyperlink.Click(); this.ScrollQuickNavigationHyperlink(hyperlink); Assert.That(section.Displayed); Assert.AreEqual(hyperlink.Text, section.Text); Assert.That(hTags.Contains(section.TagName)); } }
public new string GetAttribute(string attributeName) { return(webElement_.GetAttribute(attributeName)); }
public static string generateWebElementType(RemoteWebElement webElement) { string webCtrlType = string.Empty; if (webElement == null) { return(webCtrlType); } string tagName = webElement.TagName.ToUpper(); switch (tagName) { case "IFRAME": //This will answer queryies from our child Frames. case "FRAME": webCtrlType = "WebFrame"; break; case "HTML": webCtrlType = "WebPage"; break; case "A": if (isRealLink(webElement)) { webCtrlType = "WebLink"; } break; case "IMG": if (getImageParentAnchor(webElement) != null) { webCtrlType = "WebImageLink"; } else { webCtrlType = "WebImage"; } break; case "BUTTON": webCtrlType = "WebButton"; break; case "INPUT": string type = webElement.GetAttribute("type"); switch (type.ToLower()) { case "button": case "submit": case "reset": webCtrlType = "WebButton"; break; case "text": webCtrlType = "WebEdit"; break; case "image": webCtrlType = "WebImage"; break; case "checkbox": webCtrlType = "WebCheckBox"; break; case "radio": // Save the element which caused the radio-group to be created (_elem is the active radio-button) webCtrlType = "WebRadioGroup"; break; case "file": webCtrlType = "WebFile"; break; case "hidden": break; case "range": webCtrlType = "WebEdit"; //RangeBehavior & RangeBaseBehavior break; case "number": webCtrlType = "WebEdit"; //RangeBaseBehavior & numberBehavior break; default: webCtrlType = "WebEdit"; break; } break; case "TEXTAREA": webCtrlType = "WebEdit"; break; case "SELECT": webCtrlType = "WebList"; break; case "AREA": webCtrlType = "WebArea"; break; case "TABLE": webCtrlType = "WebTable"; break; case "VIDEO": webCtrlType = "WebVideo"; break; case "AUDIO": webCtrlType = "WebAudio"; break; case "FORM": webCtrlType = "WebForm"; break; case "OBJECT": webCtrlType = "WebPlugin"; break; case "SPAN": case "DIV": if (isElementContentEditable(webElement)) { webCtrlType = "WebEdit"; } else { webCtrlType = "WebObject"; } break; default: webCtrlType = "WebObject"; break; } return(webCtrlType); }
public string GetAttribute(string attributeName) { return(DecoratedWebElement.GetAttribute(attributeName)); }
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; } }