public IEElement(Browser browser, MSHTML.IHTMLElement Element) { Browser = browser; RawElement = Element; className = Element.className; id = Element.id; tagName = Element.tagName.ToLower(); if (tagName == "input") { MSHTML.IHTMLInputElement inputelement = Element as MSHTML.IHTMLInputElement; type = inputelement.type.ToLower(); } try { MSHTML.IHTMLUniqueName id = RawElement as MSHTML.IHTMLUniqueName; uniqueID = id.uniqueID; } catch (Exception) { } IndexInParent = -1; if (Element.parentElement != null && !string.IsNullOrEmpty(uniqueID)) { MSHTML.IHTMLElementCollection children = Element.parentElement.children; for (int i = 0; i < children.length; i++) { MSHTML.IHTMLUniqueName id = children.item(i) as MSHTML.IHTMLUniqueName; if (id != null && id.uniqueID == uniqueID) { IndexInParent = i; break; } } } }
public IEElement(Browser browser, MSHTML.IHTMLElement Element) { Browser = browser; RawElement = Element; ClassName = Element.className; Id = Element.id; TagName = Element.tagName.ToLower(); Name = ""; try { if (!(RawElement.getAttribute("Name") is System.DBNull)) { Name = (string)RawElement.getAttribute("Name"); } } catch (Exception) { } if (TagName == "option") { var option = Element as MSHTML.IHTMLOptionElement; Name = option.text; } if (TagName == "input") { MSHTML.IHTMLInputElement inputelement = Element as MSHTML.IHTMLInputElement; Type = inputelement.type.ToLower(); } try { MSHTML.IHTMLUniqueName id = RawElement as MSHTML.IHTMLUniqueName; UniqueID = id.uniqueID; } catch (Exception) { } IndexInParent = -1; if (Element.parentElement != null && !string.IsNullOrEmpty(UniqueID)) { MSHTML.IHTMLElementCollection children = (MSHTML.IHTMLElementCollection)Element.parentElement.children; for (int i = 0; i < children.length; i++) { if (children.item(i) is MSHTML.IHTMLUniqueName id && id.uniqueID == UniqueID) { IndexInParent = i; break; } } } }
public static bool Match(SelectorItem item, MSHTML.IHTMLElement m) { foreach (var p in item.Properties.Where(x => x.Enabled == true && x.Value != null)) { if (p.Name == "tagName") { if (!string.IsNullOrEmpty(m.tagName)) { var v = m.tagName; if (!PatternMatcher.FitsMask(v, p.Value)) { Log.Selector(p.Name + " mismatch '" + v + "' expected '" + p.Value + "'"); return(false); } } else { Log.Selector(p.Name + " does not exists, but needed value '" + p.Value + "'"); return(false); } } if (p.Name == "className") { var v = m.className; if (!string.IsNullOrEmpty(m.className)) { if (v.Contains(" ") && !p.Value.Contains(" ")) { var arr = v.Split(' '); var found = false; foreach (var s in arr) { if (PatternMatcher.FitsMask(s, p.Value)) { found = true; } } if (!found) { Log.Selector(p.Name + " mismatch '" + m.className + "' expected '" + p.Value + "'"); return(false); } } else if (!PatternMatcher.FitsMask(v, p.Value)) { Log.Selector(p.Name + " mismatch '" + m.className + "' expected '" + p.Value + "'"); return(false); } } else { Log.Selector(p.Name + " does not exists, but needed value '" + p.Value + "'"); return(false); } } if (p.Name == "type" && m.tagName.ToLower() == "input") { MSHTML.HTMLInputElement ele = (MSHTML.HTMLInputElement)m; if (!string.IsNullOrEmpty(ele.type)) { var v = ele.type; if (!PatternMatcher.FitsMask(ele.type, p.Value)) { Log.Selector(p.Name + " mismatch '" + v + "' expected '" + p.Value + "'"); return(false); } } else { Log.Selector(p.Name + " does not exists, but needed value '" + p.Value + "'"); return(false); } } if (p.Name == "Id") { if (!string.IsNullOrEmpty(m.id)) { var v = m.id; if (!PatternMatcher.FitsMask(m.id, p.Value)) { Log.Selector(p.Name + " mismatch '" + v + "' expected '" + p.Value + "'"); return(false); } } else { Log.Selector(p.Name + " does not exists, but needed value '" + p.Value + "'"); return(false); } } if (p.Name == "IndexInParent") { MSHTML.IHTMLUniqueName id = m as MSHTML.IHTMLUniqueName; var uniqueID = id.uniqueID; var IndexInParent = -1; if (m.parentElement != null && !string.IsNullOrEmpty(uniqueID)) { MSHTML.IHTMLElementCollection children = (MSHTML.IHTMLElementCollection)m.parentElement.children; for (int i = 0; i < children.length; i++) { MSHTML.IHTMLUniqueName id2 = children.item(i) as MSHTML.IHTMLUniqueName; if (id2.uniqueID == uniqueID) { IndexInParent = i; break; } } } if (IndexInParent != int.Parse(p.Value)) { Log.Selector(p.Name + " mismatch '" + IndexInParent + "' expected '" + p.Value + "'"); return(false); } } } return(true); }
public static string GetUniqueID(MSHTML.IHTMLElement RawElement) { MSHTML.IHTMLUniqueName id = RawElement as MSHTML.IHTMLUniqueName; return(id.uniqueID); }