Beispiel #1
0
        public override object DoRun()
        {
            var searchStrategy = new LocationHeuristictSearchStrategy(this.Selenium);
            var lookupResult   = searchStrategy.DirectLookup(TagNames, SubjectName, Locale, Direction, Order, false);

            if (Interpreter?.IsAnalysis == true)
            {
                Console.Out.WriteColoredLine(ConsoleColor.Magenta, $"Main Result: \n\t{lookupResult.MainResult}\nAll results:\n\t{string.Join("\n\t", lookupResult.AllValidResults)}");
            }

            var chromeHandle = Selenium.BrowserHandle;
            var browserBox   = new UserBindings.RECT();

            UserBindings.GetWindowRect(chromeHandle, ref browserBox);

            var e = lookupResult.AllValidResults.ElementAt(Order);

            Selenium.PutElementOnScreen(e.WebElement);

            var refreshedPosition = e.WebElement.AsBufferedElement().Rectangle;

            var centerX = refreshedPosition.X + refreshedPosition.Width / 2;
            var centerY = refreshedPosition.Y + refreshedPosition.Height / 2;

            var p = new Point(centerX, centerY);

            Selenium.ConvertFromPageToWindow(ref p);

            if (p.X < 0 || p.X > browserBox.Right || p.Y < 0 || p.Y > browserBox.Bottom)
            {
                throw new NotFoundException("Element not found");
            }
            else
            {
                if (Interpreter?.IsDebugMode == true)
                {
                    BrowserOverlay
                    .HighlightElements((Order + 1).ToString(), (Expect.ToString().ToLower().Equals(true.ToString().ToLower()) ? Color.GreenYellow : Color.Red), lookupResult.MainResult)
                    .ShowFor(750, "Highlighted element will be Clicked");
                }
                return(lookupResult.AllValidResults.ElementAt(Order).WebElement.Selected);
            }

            throw new NotFoundException("Element not found");

            throw new NotImplementedException($"Checking visibility of nth ({Order}) elements is not implemented.");
        }
Beispiel #2
0
        private bool IsInsideBoundingBox(IBufferedElement e, UserBindings.RECT browserBox)
        {
            Selenium.PutElementOnScreen(e.WebElement);

            var refreshedPosition = e.WebElement.AsBufferedElement().Rectangle;

            var centerX = refreshedPosition.X + refreshedPosition.Width / 2;
            var centerY = refreshedPosition.Y + refreshedPosition.Height / 2;

            var p = new Point(centerX, centerY);

            Selenium.ConvertFromPageToWindow(ref p);

            var isOutsideBoundingBox = p.X <0 || p.X> browserBox.Right || p.Y <0 || p.Y> browserBox.Bottom;

            return(!isOutsideBoundingBox);
        }