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 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 = 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); }