示例#1
0
        public void Init()
        {
            ElementScope table = scope.FindXPath(locators[0]);

            // body
            var tbody = table.FindXPath(".//tbody");

            RowsOfElements = new List <List <ElementScope> >();
            foreach (var tr in tbody.FindAllXPath(".//tr"))
            {
                var row = new List <ElementScope>();
                RowsOfElements.Add(row);
                foreach (var td in tr.FindAllXPath(".//td"))
                {
                    row.Add(td);
                }
            }

            // head
            if (isHeader)
            {
                ElementScope theader;
                IEnumerable <ElementScope> headerLines;
                try
                {
                    theader     = table.FindAllXPath(".//thead").First();
                    headerLines = (IEnumerable <ElementScope>)theader.FindAllXPath(".//tr");
                }
                catch (NoSuchElementException)
                {
                    theader     = table;
                    headerLines = new ElementScope[] { theader.FindAllXPath(".//tr").First() };
                    RowsOfElements.RemoveAt(0);
                }

                Header         = new List <ElementScope>();
                HeaderCaptions = new List <string>();
                foreach (var tr in headerLines)
                {
                    var cells = tr.FindAllXPath(".//th");
                    if (cells.Count() > 0)
                    {
                        if (Header.Count > 0)
                        {
                            throw new Exception(
                                      $"Too many headers in the table {locators[0]}. Contents: {theader.Text}");
                        }

                        foreach (var td in cells)
                        {
                            Header.Add(td);
                            HeaderCaptions.Add(td.Text);
                        }
                    }
                }
            }
        }
示例#2
0
        public static void FillDropDownWith(this ElementScope dropdown, string option, Options coypuOptions = null) //  метод ищет в выпадающем списке все значения, содержащие город и берет из них первый
        {
            if (coypuOptions == null)
            {
                coypuOptions = new Options()
                {
                    TextPrecision = TextPrecision.Exact, ConsiderInvisibleElements = false
                }
            }
            ;
            //var optionToSelect = dropdown.FindXPath($".//li[.='{option}']");
            Thread.Sleep(900);
            var optionsToSelect = dropdown.FindAllXPath($".//li[contains(.,'{option}')]");
            var optionToSelect  = optionsToSelect.First(f => f.Text == option);

            optionToSelect.Hover();
            Thread.Sleep(200);
            optionToSelect.Click(coypuOptions);
        }