Esempio n. 1
0
        private static ElementLocator GetCoreAttributes(HtmlAttribute xAttribute, ElementLocator locator)
        {
            if (xAttribute.Name == "class")
            {
                locator.XpathAttributes.ClassAttribute = new Attrib
                {
                    Name  = xAttribute.Name.ToString(),
                    Value = xAttribute.Value
                };
                Console.WriteLine($"Class= {xAttribute.Value}");
            }

            if (xAttribute.Name == "id")
            {
                locator.XpathAttributes.Id = new Attrib
                {
                    Name  = xAttribute.Name.ToString(),
                    Value = xAttribute.Value
                };
                Console.WriteLine($"Id = {xAttribute.Value}");
            }

            if (xAttribute.Name == "name")
            {
                locator.XpathAttributes.Name = new Attrib
                {
                    Name  = xAttribute.Name.ToString(),
                    Value = xAttribute.Value
                };
                Console.WriteLine($"Name = {xAttribute.Value}");
            }

            if (xAttribute.Name == "link")
            {
                locator.XpathAttributes.Link = new Attrib
                {
                    Name  = xAttribute.Name.ToString(),
                    Value = xAttribute.Value
                };
                Console.WriteLine($"Link Text = {xAttribute.Value}");
            }

            return(locator);
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        public void TryFindElementFromList(ElementLocator elementLocators)
        {
            foreach (var locator in elementLocators.XpathAttributes.GetAttributes)
            {
                if (locator != null)
                {
                    try
                    {
                        _seleniumOperations = new SeleniumOperations();
                        if (string.Equals(locator.Name, "class", StringComparison.CurrentCultureIgnoreCase))
                        {
                            _seleniumOperations.ClickOnElementClassName("k");;
                            Console.WriteLine($"Getting By Class {locator.Value}");
                            break;
                        }

                        if (locator.Name.ToLower() == "id".ToLower())
                        {
                            _seleniumOperations.ClickOnElementId(locator.Value);
                            Console.WriteLine($"Getting By ID {locator.Value}");
                            break;
                        }

                        if (locator.Name.ToLower() == "name".ToLower())
                        {
                            _seleniumOperations.ClickOnElementClassName(locator.Value);
                        }

                        if (locator.Name.ToLower() == "link".ToLower())
                        {
                            _seleniumOperations.ClickOnElementClassName(locator.Value);
                        }
                    }
                    catch (NoSuchElementException e)
                    {
                        Console.WriteLine(e);
                        _seleniumOperations.CloseDriver();
                    }
                }
            }
        }