public async Task <string> ClickElement(string elementId)
        {
            if (_asyncChromeDriver != null)
            {
                await _asyncChromeDriver.CheckConnected().ConfigureAwait(false);
            }
            var tagName = await _elementUtils.GetElementTagName(elementId).ConfigureAwait(false);

            if (tagName == "option")
            {
                bool isToggleable = await _elementUtils.IsOptionElementTogglable(elementId).ConfigureAwait(false);

                if (isToggleable)
                {
                    await _elementUtils.ToggleOptionElement(elementId).ConfigureAwait(false);

                    return("ToggleOptionElement");
                }
                else
                {
                    await _elementUtils.SetOptionElementSelected(elementId).ConfigureAwait(false);

                    return("SetOptionElementSelected");
                }
            }
            else
            {
                WebPoint location = await _elementUtils.GetElementClickableLocation(elementId).ConfigureAwait(false);

                await _webView.DevTools.Input.DispatchMouseEvent(new ChromeDevTools.Input.DispatchMouseEventCommand {
                    Type = ChromeDriverMouse.MovedMouseEventType, Button = ChromeDevTools.Input.MouseButton.None, X = location.X, Y = location.Y, Modifiers = Session.StickyModifiers, ClickCount = 0
                }).ConfigureAwait(false);

                await _webView.DevTools.Input.DispatchMouseEvent(new ChromeDevTools.Input.DispatchMouseEventCommand {
                    Type = ChromeDriverMouse.PressedMouseEventType, Button = ChromeDevTools.Input.MouseButton.Left, X = location.X, Y = location.Y, Modifiers = Session.StickyModifiers, ClickCount = 1
                }).ConfigureAwait(false);

                await _webView.DevTools.Input.DispatchMouseEvent(new ChromeDevTools.Input.DispatchMouseEventCommand {
                    Type = ChromeDriverMouse.ReleasedMouseEventType, Button = ChromeDevTools.Input.MouseButton.Left, X = location.X, Y = location.Y, Modifiers = Session.StickyModifiers, ClickCount = 1
                }).ConfigureAwait(false);

                Session.MousePosition = location;
                //await new ChromeDriverMouse(webView).Click(location);
                return("Click");
            }
        }
Пример #2
0
        public async Task <string> ClickElement(string elementId)
        {
            await asyncChromeDriver.CheckConnected();

            var tag_name = await elementUtils.GetElementTagName(elementId);

            if (tag_name == "option")
            {
                bool is_toggleable = await elementUtils.IsOptionElementTogglable(elementId);

                if (is_toggleable)
                {
                    await elementUtils.ToggleOptionElement(elementId);

                    return("ToggleOptionElement");
                }
                else
                {
                    await elementUtils.SetOptionElementSelected(elementId);

                    return("SetOptionElementSelected");
                }
            }
            else
            {
                WebPoint location = await elementUtils.GetElementClickableLocation(elementId);

                var res = await webView.DevTools.Session.Input.DispatchMouseEvent(new BaristaLabs.ChromeDevTools.Runtime.Input.DispatchMouseEventCommand
                {
                    Type       = ChromeDriverMouse.MovedMouseEventType,
                    Button     = ChromeDriverMouse.NoneMouseButton,
                    X          = location.X,
                    Y          = location.Y,
                    Modifiers  = Session.sticky_modifiers,
                    ClickCount = 0
                });

                res = await webView.DevTools.Session.Input.DispatchMouseEvent(new BaristaLabs.ChromeDevTools.Runtime.Input.DispatchMouseEventCommand
                {
                    Type       = ChromeDriverMouse.PressedMouseEventType,
                    Button     = ChromeDriverMouse.LeftMouseButton,
                    X          = location.X,
                    Y          = location.Y,
                    Modifiers  = Session.sticky_modifiers,
                    ClickCount = 1
                });

                res = await webView.DevTools.Session.Input.DispatchMouseEvent(new BaristaLabs.ChromeDevTools.Runtime.Input.DispatchMouseEventCommand
                {
                    Type       = ChromeDriverMouse.ReleasedMouseEventType,
                    Button     = ChromeDriverMouse.LeftMouseButton,
                    X          = location.X,
                    Y          = location.Y,
                    Modifiers  = Session.sticky_modifiers,
                    ClickCount = 1
                });

                Session.mouse_position = location;
                //await new ChromeDriverMouse(webView).Click(location);
                return("Click");
            }
        }