示例#1
0
        private string GetPicBase64Data(IWebDriver iframeElWebDriver)
        {
            string str;

            try
            {
                string zhuRuJs = Resources.getBase64Image_tbdj;
                str = (string)SelementHelper.ExecJs(iframeElWebDriver, zhuRuJs, null);
                return(str);
            }
            catch (Exception exception)
            {
                Exception ex = exception;
                XLog.Debug(string.Concat("GetPicBase64Data ", ex.ToString()), Array.Empty <object>());
            }
            str = null;
            return(str);
        }
示例#2
0
        public bool Run(IWebDriver IframeElWebDriver)
        {
            PointX      bigYuan;
            PointX      samllYuan;
            bool        isSuc         = false;
            IWebElement bgEl          = IframeElWebDriver.FinElement(By.ClassName("bg-placeholder"));
            IWebElement slideEl       = IframeElWebDriver.FinElement(By.Id("slide-block"));
            IWebElement smallE1       = IframeElWebDriver.FinElement(By.XPath("//div[@id=\"slide-block\"]/img")) ?? IframeElWebDriver.FinElement(By.XPath("/html/body/div[1]/div[2]/div[1]/div[2]/img"));
            IWebElement bgCanvasEl    = IframeElWebDriver.FinElement(By.Id("canvas"));
            IWebElement dragBtuttonEl = IframeElWebDriver.FinElement(By.ClassName("drag-button"));
            IWebElement dragTrackEl   = IframeElWebDriver.FinElement(By.ClassName("drag-track"));

            if ((bgEl == null || smallE1 == null || dragBtuttonEl == null ? false : bgCanvasEl != null))
            {
                string smallPicSrc = smallE1.GetAttribute("src");
                string bigPicSrc   = SelementHelper.ExecJs(IframeElWebDriver, "return document.getElementById('canvas').toDataURL()", Array.Empty <object>()) as string;
                if ((bigPicSrc == null ? false : smallPicSrc != null))
                {
                    int    samllLocationY = smallE1.Location.Y - bgCanvasEl.Location.Y;
                    int    smallShiJiY    = (int)((double)samllLocationY * 1.20805369127517 - 1);
                    PointX p = this.GetPoint(bigPicSrc, smallPicSrc, smallShiJiY, out bigYuan, out samllYuan);
                    if (p != null)
                    {
                        double x        = (double)bigYuan.X;
                        Size   size     = bgEl.Size;
                        double elWidthP = x / (double)size.Width;
                        size = bgEl.Size;
                        double  smallYinBig = (double)size.Height / (double)bigYuan.Y;
                        int     sjX         = HelperGeneral.Random.Next(13, 53);
                        int     sjY         = HelperGeneral.Random.Next(13, 53);
                        int     ysX         = sjX;
                        int     ysY         = sjY;
                        double  dianJianP_X = (double)ysX;
                        double  tageX_left  = (double)p.X / (double)elWidthP;
                        double  tageX       = tageX_left + dianJianP_X;
                        double  k           = 0.938;
                        double  d           = 256 + dianJianP_X - tageX;
                        double  realX       = tageX - (1 - k) / k * d;
                        int     realY       = p.Y + sjY;
                        Actions actions     = new Actions(IframeElWebDriver);
                        SelementHelper.MoveTo(IframeElWebDriver, smallE1, ysX, ysY);
                        actions.ClickAndHold().Perform();
                        XTrace.WriteLine("开始移动到{tageX}");
                        this.MouseMoveTaget((int)realX, realY, actions, dragBtuttonEl, tageX_left, dianJianP_X, slideEl, bgEl, dragTrackEl, IframeElWebDriver);
                        actions.MoveToElement(bgEl, (int)realX, realY).Perform();
                        Thread.Sleep(2000);
                        double smallLeft = this.GetSmallElLeft(slideEl);
                        double dragLeft  = this.GetDragBtuttonElLeft(dragBtuttonEl);
                        if (Math.Abs(realX - dianJianP_X - dragLeft) > 1)
                        {
                            XTrace.WriteLine(string.Format("当前模块位置 {0} 目标位置{1}    小图片当前左上角位置{2}", dragLeft, realX - dianJianP_X, smallLeft));
                            actions.MoveToElement(bgEl, (int)realX, 20).Perform();
                            Thread.Sleep(300);
                        }
                        else
                        {
                            XTrace.WriteLine(string.Format("到达目标点{0} 当前按钮位置{1}   小图片当前左上角位置{2}  目的左上角{3}", new object[] { realX - dianJianP_X, dragLeft, smallLeft, tageX_left }));
                            Thread.Sleep(1000);
                        }
                        XTrace.WriteLine("松开鼠标...");
                        actions.Release().Perform();
                        Thread.Sleep(2000);
                        isSuc = true;
                        Thread.Sleep(1000);
                    }
                }
            }
            return(isSuc);
        }