private bool GetCategoryGoodsItems(int pageIndex)
        {
            bool hasNewElement = false;
            ReadOnlyCollection <AndroidElement> allLinearLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout", true);

            foreach (AppiumWebElement element in allLinearLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> imageElements = element.FindElementsByClassName("android.widget.ImageView");
                ReadOnlyCollection <AppiumWebElement> textElements  = element.FindElementsByClassName("android.widget.TextView");
                if (imageElements != null && imageElements.Count > 0 && textElements != null && textElements.Count >= 2)
                {
                    AppiumWebElement nameElement  = textElements[textElements.Count - 2];
                    AppiumWebElement priceElement = textElements[textElements.Count - 1];
                    string           id           = nameElement.Text + priceElement.Text;
                    if (!GoodsElementList.Exist(id) && !nameElement.Text.StartsWith("¥") && priceElement.Text.StartsWith("¥"))
                    {
                        Point         location   = new Point(element.Location.X, element.Location.Y);
                        NcpAppElement appElement = GoodsElementList.Add(id, nameElement.Text, "", location, element.Size);
                        appElement.Attributes.Add("price", priceElement.Text.Substring(1));
                        hasNewElement = true;
                    }
                }
            }
            if (!hasNewElement && hasNoneNewElementTime == 0)
            {
                hasNoneNewElementTime++;
                hasNewElement = true;
            }
            return(hasNewElement);
        }
        private bool GetCategoryItems(int pageIndex)
        {
            int  pageOffset    = pageIndex * 2000;
            bool hasNewElement = false;
            ReadOnlyCollection <AndroidElement> allRelativeLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout", true);

            foreach (AppiumWebElement element in allRelativeLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> textElements = element.FindElementsByClassName("android.widget.TextView");
                if (textElements != null && textElements.Count >= 2)
                {
                    //需要改造,将名称+宽度作为唯一标识,因为商品数量经常变
                    //获取某类下的所有商品时,商品数量要按抓取此分类时的数量为准
                    //增加店铺名的抓取
                    AppiumWebElement nameElement  = textElements[0];
                    AppiumWebElement countElement = textElements[1];
                    string           id           = nameElement.Text + countElement.Text;
                    if (!_CategoryElementList.Exist(id))
                    {
                        Point         location   = new Point(element.Location.X, element.Location.Y + pageOffset);
                        NcpAppElement appElement = CategoryElementList.Add(id, nameElement.Text, "Level1", location, element.Size);
                        appElement.Attributes.Add("count", countElement.Text.Substring(1, countElement.Text.Length - 2));
                        hasNewElement = true;
                    }
                }
            }

            ReadOnlyCollection <AndroidElement> allLinearLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout", true);

            foreach (AppiumWebElement element in allLinearLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> textElements = element.FindElementsByClassName("android.widget.TextView");
                if (textElements != null && textElements.Count >= 2)
                {
                    AppiumWebElement nameElement  = textElements[0];
                    AppiumWebElement countElement = textElements[1];
                    string           id           = nameElement.Text + countElement.Text;
                    if (!_CategoryElementList.Exist(id))
                    {
                        Point         location   = new Point(element.Location.X, element.Location.Y + pageOffset);
                        NcpAppElement appElement = CategoryElementList.Add(id, nameElement.Text, "Level2", location, element.Size);
                        appElement.Attributes.Add("count", countElement.Text.Substring(1, countElement.Text.Length - 2));
                        hasNewElement = true;
                    }
                }
            }

            return(hasNewElement);
        }
Example #3
0
        private NcpAppElementList GetCategory1Items()
        {
            NcpAppElementList allC1Elements = new NcpAppElementList();
            //ReadOnlyCollection<AndroidElement> allC1Nodes = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.TextView[1]", true);
            ReadOnlyCollection <AndroidElement> allC1Nodes = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView[1]", true);

            foreach (AppiumWebElement c1Node in allC1Nodes)
            {
                NcpAppElement c1Element = new NcpAppElement();
                c1Element.Name = c1Node.Text;
                c1Element.Id   = c1Element.Name;
                allC1Elements.Add(c1Element);
            }
            return(allC1Elements);
        }
        private AppiumWebElement GetCategoryElement(string name, string count)
        {
            ReadOnlyCollection <AndroidElement> allRelativeLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.RelativeLayout", true);

            foreach (AppiumWebElement element in allRelativeLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> textElements = element.FindElementsByClassName("android.widget.TextView");
                if (textElements != null && textElements.Count >= 2)
                {
                    AppiumWebElement nameElement  = textElements[0];
                    AppiumWebElement countElement = textElements[1];
                    if (nameElement.Text == name && countElement.Text == "(" + count + ")")
                    {
                        return(element);
                    }
                }
            }

            ReadOnlyCollection <AndroidElement> allLinearLayouts = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout", true);

            foreach (AppiumWebElement element in allLinearLayouts)
            {
                ReadOnlyCollection <AppiumWebElement> textElements = element.FindElementsByClassName("android.widget.TextView");
                if (textElements != null && textElements.Count >= 2)
                {
                    AppiumWebElement nameElement  = textElements[0];
                    AppiumWebElement countElement = textElements[1];
                    if (nameElement.Text == name && countElement.Text == "(" + count + ")")
                    {
                        return(element);
                    }
                }
            }

            try
            {
                Size winSize = AppAccess.GetWindowSize();
                AppAccess.Swipe(new Point(winSize.Width - 20, winSize.Height - 20),
                                new Point(winSize.Width - 20, 200),
                                2000);
                Thread.Sleep(3000);
                return(this.GetCategoryElement(name, count));
            }
            catch (Exception ex)
            {
                throw new Exception("找不到分类元素, name = " + name + ", count = " + count, ex);
            }
        }