private void BtnScrape_Click(object sender, EventArgs e)
        {
            if (BtnLaunch.Enabled)
            {
                return;
            }
            if (LvLocators.Items.Count > 0)
            {
                LvLocators.Items.Clear();
            }
            ElementChecker ec     = new ElementChecker(driver, driver.PageSource);
            Scrape         scrape = new Scrape();

            scrape.ShowDialog();
            if (scrape.DialogResult == DialogResult.OK)
            {
                tags = scrape.GetCheckedItems();
            }
            foreach (var tag in tags)
            {
                IReadOnlyCollection <IWebElement> elms = driver.FindElements(By.TagName(tag));
                foreach (var elm in elms)
                {
                    if (elm.Displayed)
                    {
                        UniqueData ud = ec.CheckUniqueness(new WrappedElement(driver, elm));
                        if (ud.type != null)
                        {
                            ListViewItem item = new ListViewItem();
                            string[]     data = { VariableName.Name(elm), tag, ud.type.ToString(), ud.value.ToString() };
                            ListViewItem lvi  = new ListViewItem(data);
                            LvLocators.Items.Add(lvi);
                        }
                    }
                }
            }
            //this.TopMost = true;
        }
Beispiel #2
0
        public UniqueData CheckUniqueness(WrappedElement elm)
        {
            string     retData = null;
            UniqueData ud      = new UniqueData();

            if (!String.IsNullOrEmpty(elm.Id) && IsUnique(LocatoryType.Id, elm.Tag, elm.Id, out retData))
            {
                ud.type  = "id";
                ud.value = elm.Id;
            }
            else if (!String.IsNullOrEmpty(elm.Name) && IsUnique(LocatoryType.Name, elm.Tag, elm.Name, out retData))
            {
                ud.type  = "name";
                ud.value = elm.Name;
            }
            else if (!String.IsNullOrEmpty(elm.ClassName) && IsUnique(LocatoryType.Class, elm.Tag, elm.ClassName, out retData))
            {
                if (String.IsNullOrEmpty(retData))
                {
                    ud.type  = "class";
                    ud.value = elm.ClassName;
                }
                else
                {
                    ud.type  = "xpath";
                    ud.value = retData;
                }
            }
            else if (!String.IsNullOrEmpty(elm.Text) && IsUnique(LocatoryType.Text, elm.Tag, elm.Text, out retData))
            {
                if (String.IsNullOrEmpty(retData))
                {
                    ud.type  = "text";
                    ud.value = elm.Text;
                }
                else
                {
                    ud.type  = "xpath";
                    ud.value = retData;
                }
            }
            else
            {
                string xp = CheckXpathWithSingleAttribute(elm);
                if (!String.IsNullOrEmpty(xp))
                {
                    ud.type  = "xpath";
                    ud.value = xp;
                }
                else
                {
                    xp = CheckXpathWithSingleAttributeAndText(elm);
                    if (!String.IsNullOrEmpty(xp))
                    {
                        ud.type  = "xpath";
                        ud.value = xp;
                    }
                    else
                    {
                        xp = CheckXpathWithDoubleAttribute(elm);
                        if (!String.IsNullOrEmpty(xp))
                        {
                            ud.type  = "xpath";
                            ud.value = xp;
                        }
                        else
                        {
                            xp = CheckXpathWithDoubleAttributeAndText(elm);
                            if (!String.IsNullOrEmpty(xp))
                            {
                                ud.type  = "xpath";
                                ud.value = xp;
                            }
                            else
                            {
                                xp = CheckXpathWithParent(elm);
                                if (!String.IsNullOrEmpty(xp))
                                {
                                    ud.type  = "xpath";
                                    ud.value = xp;
                                }
                                else
                                {
                                    xp = CheckXPathWithGrandParent(elm);
                                    if (!String.IsNullOrEmpty(xp))
                                    {
                                        ud.type  = "xpath";
                                        ud.value = xp;
                                    }
                                    else
                                    {
                                        xp = CheckXPathWithFollowingSibling(elm);
                                        if (!String.IsNullOrEmpty(xp))
                                        {
                                            ud.type  = "xpath";
                                            ud.value = xp;
                                        }
                                        else
                                        {
                                            xp = CheckXPathWithPrecedingSibling(elm);
                                            if (!String.IsNullOrEmpty(xp))
                                            {
                                                ud.type  = "xpath";
                                                ud.value = xp;
                                            }
                                            else
                                            {
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (single != null)
                {
                    if (single.Count > 0)
                    {
                        single.Clear();
                    }
                }
                if (singletext != null)
                {
                    if (singletext.Count > 0)
                    {
                        singletext.Clear();
                    }
                }
                if (doub != null)
                {
                    if (doub.Count > 0)
                    {
                        doub.Clear();
                    }
                }
                if (doubtext != null)
                {
                    if (doubtext.Count > 0)
                    {
                        doub.Clear();
                    }
                }
                if (parnt != null)
                {
                    if (parnt.Count > 0)
                    {
                        parnt.Clear();
                    }
                }
            }
            return(ud);
        }