/// <summary> /// Wrapper around getElementsByTagName /// </summary> /// <param name="tagName">tagName is the name of the tag to look for, e.g. "input"</param> /// <param name="retrieveAttributes">If true then all attributes are retrieved. This is slow!</param> /// <returns></returns> public List <ElementContainer> GetElementsByTagName(string tagName, string[] attributes) { List <ElementContainer> elements = new List <ElementContainer>(); foreach (IHTMLElement element in document3.getElementsByTagName(tagName)) { if (element.offsetWidth <= 0 || element.offsetHeight <= 0) { // not visisble continue; } ElementContainer elementContainer = new ElementContainer(); elementContainer.id = element.id; if (attributes != null) { foreach (string attributeName in attributes) { object attributeValue = element.getAttribute(attributeName, 0); if (attributeValue != null && attributeValue != DBNull.Value && !elementContainer.attributes.ContainsKey(attributeName)) { elementContainer.attributes.Add(attributeName, attributeValue.ToString()); } } } Point elementLocation = new Point((int)element.offsetLeft, (int)element.offsetTop); elementLocation.Offset(this.DestinationLocation); IHTMLElement parent = element.offsetParent; while (parent != null) { elementLocation.Offset((int)parent.offsetLeft, (int)parent.offsetTop); parent = parent.offsetParent; } Rectangle elementRectangle = new Rectangle(elementLocation, new Size((int)element.offsetWidth, (int)element.offsetHeight)); elementContainer.rectangle = elementRectangle; elements.Add(elementContainer); } return(elements); }
/// <summary> /// Wrapper around getElementsByTagName /// </summary> /// <param name="tagName">tagName is the name of the tag to look for, e.g. "input"</param> /// <param name="retrieveAttributes">If true then all attributes are retrieved. This is slow!</param> /// <returns></returns> public List<ElementContainer> GetElementsByTagName(string tagName, string[] attributes) { List<ElementContainer> elements = new List<ElementContainer>(); foreach(IHTMLElement element in document3.getElementsByTagName(tagName)) { if (element.offsetWidth <= 0 || element.offsetHeight <= 0) { // not visisble continue; } ElementContainer elementContainer = new ElementContainer(); elementContainer.id = element.id; if (attributes != null) { foreach(string attributeName in attributes) { object attributeValue = element.getAttribute(attributeName, 0); if (attributeValue != null && attributeValue != DBNull.Value && !elementContainer.attributes.ContainsKey(attributeName)) { elementContainer.attributes.Add(attributeName, attributeValue.ToString()); } } } Point elementLocation = new Point((int)element.offsetLeft, (int)element.offsetTop); elementLocation.Offset(this.DestinationLocation); IHTMLElement parent = element.offsetParent; while (parent != null) { elementLocation.Offset((int)parent.offsetLeft, (int)parent.offsetTop); parent = parent.offsetParent; } Rectangle elementRectangle = new Rectangle(elementLocation, new Size((int)element.offsetWidth, (int)element.offsetHeight)); elementContainer.rectangle = elementRectangle; elements.Add(elementContainer); } return elements; }