public void GetAllLocatorsXpath(string xpathLocator, ElementLocators elementLocators) { var elements = elementLocators.Locators.Where(x => x.Xpath.Equals("/html/body/div/table")); //PrintAllResults(elements); foreach (var elementLocator in elements) { TryFindElementFromList(elementLocator); } }
public static void Main() { _elementLocators = new ElementLocators { Locators = new List <ElementLocator>() }; var doc = new HtmlDocument(); doc.Load("C:\\Users\\trice\\source\\repos\\DomParser\\DomParser\\new2.html"); var allElements = doc.DocumentNode.SelectNodes("descendant::*").ToArray(); foreach (var element in allElements) { var locator = new ElementLocator { XpathAttributes = new XpathAttributes() }; var elementAttributes = ""; _attribs = element.Attributes; foreach (var xAttribute in _attribs) { elementAttributes += $" {xAttribute.Name}: {xAttribute.Value},"; locator = GetCoreAttributes(xAttribute, locator); } locator.Xpath = GenerateXpath(element); Console.Write($"XPath: {GenerateXpath(element)}\n"); locator.Element = $"{element.Name}-{elementAttributes}"; Console.WriteLine($"Element: {element.Name}-{elementAttributes}\n"); _elementLocators.Locators.Add(locator); } ////FOR TESTING var elementLocator = new Locator(); elementLocator.GetAllLocatorsXpath(_elementLocators.Locators.LastOrDefault().Xpath, _elementLocators); Console.ReadLine(); }