public void PollElements(ElementIdentifier identifier, HtmlElement relativeTo, TimeSpan timeout, Action <List <HtmlElement> > callback) { //Make initial pass at finding element synchronously (in case element is there, don't waste time starting a task) List <HtmlElement> results = FindElements(identifier, relativeTo); if (results.Count > 0) { callback(results); return; } //If initial pass returns nothing, start polling task Task.Factory.StartNew(() => { DateTime start = DateTime.Now; bool stop = false; while (!stop) { ThreadingUtils.InvokeControlAction(Browser, ctl => { List <HtmlElement> pollResults = FindElements(identifier, relativeTo); if (pollResults.Count > 0 || DateTime.Now.Subtract(start) >= timeout) { stop = true; callback(pollResults); } }); Thread.Sleep(100); } }); }
public ElementIdentifier RelativeTo(ElementIdentifier baseElement) { if (baseElement != null) { ElementIdentifier relative = new ElementIdentifier(); Dictionary <string, string> baseAnchorDictionary = baseElement.ToAnchorDictionary(); Dictionary <string, string> targetAnchorDictionary = this.ToAnchorDictionary(); foreach (string baseAnchor in baseAnchorDictionary.Keys) { string basePath = baseAnchorDictionary[baseAnchor]; string targetPath; if (targetAnchorDictionary.TryGetValue(baseAnchor, out targetPath)) { string[] baseParts = basePath.Split('/'); string[] targetParts = targetPath.Split('/'); string relativePath; if (baseParts.Length == targetParts.Length) { relativePath = "."; } else { relativePath = String.Join("/", targetParts, baseParts.Length, targetParts.Length - baseParts.Length); } relativePath = String.Format("/{0}", relativePath); relative.Identifiers.Add(relativePath); //We only need one path here relative to the base because all paths relative to base paths of matching anchors will be the same. return(relative); } } } return(null); }
public ElementIdentifier Copy() { ElementIdentifier copy = new ElementIdentifier(); copy.Identifiers.AddRange(this.Identifiers); return(copy); }
public static ElementIdentifier FromHtmlElement(HtmlElement element) { ElementIdentifier identifier = new ElementIdentifier(); zBuildElementPaths(element, identifier.Identifiers); return(identifier); }
public static ElementIdentifier Copy(ElementIdentifier original) { if (original != null) { return(original.Copy()); } return(null); }
public ElementIdentifier AbsoluteTo(ElementIdentifier baseElement) { if (baseElement != null) { ElementIdentifier absolute = new ElementIdentifier(); string relativePath = this.PrimaryIdentifier; foreach (string identifier in baseElement.Identifiers) { absolute.Identifiers.Add(String.Format("{0}{1}", identifier, relativePath)); } return(absolute); } return(null); }
public ElementIdentifier RemoveSelector() { ElementIdentifier selectorRemoved = new ElementIdentifier(); foreach (string identifier in Identifiers) { if (!identifier.EndsWith(zGetAnchor(identifier))) { int lastSlashIndex = identifier.LastIndexOf('/'); int lastBracketIndex = identifier.LastIndexOf('['); selectorRemoved.Identifiers.Add(lastBracketIndex > lastSlashIndex ? identifier.Remove(lastBracketIndex) : identifier); } } return(selectorRemoved); }
public ElementIdentifier GetParent() { ElementIdentifier parent = new ElementIdentifier(); foreach (string identifier in Identifiers) { string[] parts = identifier.Split(new char[] { '/' }); if (parts.Length > 1 && parts[parts.Length - 2] != String.Empty) { string parentPath = String.Join("/", parts, 0, parts.Length - 1); parent.Identifiers.Add(parentPath); } } return(parent); }
public List <HtmlElement> FindElements(ElementIdentifier identifier, HtmlElement relativeTo) { List <HtmlElement> results = new List <HtmlElement>(); HtmlElement baseElement = relativeTo; if (baseElement == null) { baseElement = m_Browser.Document != null ? m_Browser.Document.Body : null; } //Double slashes (//) will result in a blank array entry. zRecursiveFindElements will treat the empty entry as a descendant indicator. //The first blank element of the array is skipped, which is why the array index starts at 1. foreach (string path in identifier.Identifiers) { string[] pathArray = path.Split(new char[] { '/' }, StringSplitOptions.None); zRecursiveFindElements(pathArray, 1, baseElement, results); if (results.Count > 0) { break; } } return(results); }
public void PollElements(ElementIdentifier identifier, HtmlElement relativeTo, Action <List <HtmlElement> > callback) { PollElements(identifier, relativeTo, m_DefaultPollingTimeout, callback); }
public void PollElements(ElementIdentifier identifier, TimeSpan timeout, Action <List <HtmlElement> > callback) { PollElements(identifier, null, timeout, callback); }
public void PollElement(ElementIdentifier identifier, HtmlElement relativeTo, TimeSpan timeout, Action <HtmlElement> callback) { PollElements(identifier, relativeTo, timeout, (elementList) => callback(elementList.SingleOrDefault())); }
public void PollElement(ElementIdentifier identifier, Action <HtmlElement> callback) { PollElement(identifier, m_DefaultPollingTimeout, callback); }
public List <HtmlElement> FindElements(ElementIdentifier identifier) { return(FindElements(identifier, null)); }
public HtmlElement FindElement(ElementIdentifier identifier, HtmlElement relativeTo) { return(FindElements(identifier, relativeTo).SingleOrDefault()); }
public HtmlElement FindElement(ElementIdentifier identifier) { return(FindElement(identifier, null)); }