Exemplo n.º 1
0
        public void SetCursorPos(double x, double y)
        {
            var virtualScreenPoint = ScreenCoordinatesHelper.ScreenPointToVirtualScreenPoint(new Point(x, y));

            this.mouseSimulator.MoveMouseToPositionOnVirtualDesktop(virtualScreenPoint.X, virtualScreenPoint.Y);
            Thread.Sleep(250);
        }
Exemplo n.º 2
0
        public static void HighlightElement(object userUIElementThatWeWantToHighlight, Rectangle rectangleUsedToHighlight, DotNetBrowser.Browser browser)
        {
            bool wasElementHighlighted = false;

            if (userUIElementThatWeWantToHighlight != null)
            {
                try
                {
                    // Get the coordinates of the element in HTML:
                    string uniqueIdentifier = ((dynamic)((dynamic)userUIElementThatWeWantToHighlight).INTERNAL_OuterDomElement).UniqueIdentifier.ToString();
                    if (uniqueIdentifier != null)
                    {
                        string coordinates = browser.ExecuteJavaScriptAndReturnValue(string.Format(
                                                                                         @"var div = document.getElementById('{0}');
                              var rect = div.getBoundingClientRect();
                              var result = rect.top + ';' + rect.right + ';' + rect.bottom + ';' + rect.left;
                              result;
                              ", uniqueIdentifier)).ToString();

                        string[] coordinatesArray = coordinates.Replace(',', '.').Split(';');
                        double   top    = double.Parse(coordinatesArray[0]);
                        double   right  = double.Parse(coordinatesArray[1]);
                        double   bottom = double.Parse(coordinatesArray[2]);
                        double   left   = double.Parse(coordinatesArray[3]);

                        // Take into account the screen DPI:
                        double dpiAwareTop    = ScreenCoordinatesHelper.ConvertWidthOrNaNToDpiAwareWidthOrNaN(top, invert: false);
                        double dpiAwareRight  = ScreenCoordinatesHelper.ConvertWidthOrNaNToDpiAwareWidthOrNaN(right, invert: false);
                        double dpiAwareBottom = ScreenCoordinatesHelper.ConvertWidthOrNaNToDpiAwareWidthOrNaN(bottom, invert: false);
                        double dpiAwareLeft   = ScreenCoordinatesHelper.ConvertWidthOrNaNToDpiAwareWidthOrNaN(left, invert: false);

                        Canvas.SetLeft(rectangleUsedToHighlight, dpiAwareLeft);
                        Canvas.SetTop(rectangleUsedToHighlight, dpiAwareTop);
                        rectangleUsedToHighlight.Width      = (dpiAwareRight > dpiAwareLeft ? (dpiAwareRight - dpiAwareLeft) : 0);
                        rectangleUsedToHighlight.Height     = (dpiAwareBottom > dpiAwareTop ? (dpiAwareBottom - dpiAwareTop) : 0);
                        rectangleUsedToHighlight.Visibility = Visibility.Visible;

                        // Remember the highlighted element reference:
                        rectangleUsedToHighlight.Tag = userUIElementThatWeWantToHighlight;

                        wasElementHighlighted = true;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }

            // Remove highlight if error or empty:
            if (!wasElementHighlighted)
            {
                rectangleUsedToHighlight.Width      = double.NaN;
                rectangleUsedToHighlight.Height     = double.NaN;
                rectangleUsedToHighlight.Visibility = Visibility.Collapsed;
            }
        }
        public Point GetCoordinates()
        {
            var visualRoot = WiniumVirtualRoot.Current.VisualRoot.Element;
            var element    = this.Element;

            var point  = element.TransformToVisual(visualRoot).TransformPoint(new Point(0, 0));
            var center = new Point(point.X + (int)(element.ActualWidth / 2), point.Y + (int)(element.ActualHeight / 2));

            return(ScreenCoordinatesHelper.LogicalPointToScreenPoint(center));
        }
        internal Rect GetRect()
        {
            var visualRoot = WiniumVirtualRoot.Current.VisualRoot.Element;
            var element    = this.Element;

            var point1 = element.TransformToVisual(visualRoot).TransformPoint(new Point(0, 0));
            var point2 = new Point(point1.X + element.ActualWidth, point1.Y + element.ActualHeight);

            var scrPoint1 = ScreenCoordinatesHelper.LogicalPointToScreenPoint(point1);
            var scrPoint2 = ScreenCoordinatesHelper.LogicalPointToScreenPoint(point2);

            return(new Rect(scrPoint1, scrPoint2));
        }
Exemplo n.º 5
0
        public static object GetElementAtSpecifiedCoordinates(Point coordinates)
        {
            // Find the "Core" assembly among the loaded assemblies:
            Assembly coreAssembly =
                (from a in AppDomain.CurrentDomain.GetAssemblies()
                 where a.GetName().Name == Constants.NAME_OF_CORE_ASSEMBLY ||
                 a.GetName().Name == Constants.NAME_OF_CORE_ASSEMBLY_USING_BRIDGE ||
                 a.GetName().Name == Constants.NAME_OF_CORE_ASSEMBLY_SLMIGRATION ||
                 a.GetName().Name == Constants.NAME_OF_CORE_ASSEMBLY_SLMIGRATION_USING_BRIDGE ||
                 a.GetName().Name == Constants.NAME_OF_CORE_ASSEMBLY_USING_BLAZOR ||
                 a.GetName().Name == Constants.NAME_OF_CORE_ASSEMBLY_SLMIGRATION_USING_BLAZOR
                 select a).FirstOrDefault();

            if (coreAssembly != null)
            {
                // Find the type "VisualTreeHelper" in Core:
                Type manager = (from type in coreAssembly.GetTypes() where (type.Namespace == "CSHTML5.Internal" && type.Name == "INTERNAL_HtmlDomManager") select type).FirstOrDefault();
                if (manager != null)
                {
                    // Call the "GetAllRootUIElements" method:
                    var methodInfo = manager.GetMethod("FindElementInHostCoordinates_UsedBySimulatorToo", BindingFlags.Public | BindingFlags.Static);
                    if (methodInfo != null)
                    {
                        double dpiAwareX = ScreenCoordinatesHelper.ConvertWidthOrNaNToDpiAwareWidthOrNaN(coordinates.X, invert: true);
                        double dpiAwareY = ScreenCoordinatesHelper.ConvertWidthOrNaNToDpiAwareWidthOrNaN(coordinates.Y, invert: true);

                        var element = methodInfo.Invoke(null, new object[] { dpiAwareX, dpiAwareY });
                        return(element);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
        public Point GetCoordinatesInView()
        {
            // TODO reasearch posibility to replace this code to GetClickablePoint()
            var visualRoot = WiniumVirtualRoot.Current.VisualRoot.Element;
            var element    = this.Element;

            var point        = element.TransformToVisual(visualRoot).TransformPoint(new Point(0, 0));
            var center       = new Point(point.X + (int)(element.ActualWidth / 2), point.Y + (int)(element.ActualHeight / 2));
            var bounds       = new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
            var boundsInView = new Rect(new Point(0, 0), visualRoot.RenderSize);

            boundsInView.Intersect(bounds);

            var result = boundsInView.IsEmpty
                             ? center
                             : new Point(
                boundsInView.X + (int)(boundsInView.Width / 2),
                boundsInView.Y + (int)(boundsInView.Height / 2));

            return(ScreenCoordinatesHelper.LogicalPointToScreenPoint(result));
        }