public async Task <WebPoint> ScrollElementRegionIntoViewHelper(string elementId, WebRect region, bool center = true, string clickableElementId = null, CancellationToken cancellationToken = new CancellationToken())
        {
            var res = await webView.CallFunction(atoms.GET_LOCATION_IN_VIEW, $"{{\"{GetElementKey()}\":\"{elementId}\"}}, {center.ToString().ToLower()}, {WebRectToJsonString(region)}", null, true, false, cancellationToken);

            var location = ResultValueConverter.ToWebPoint(res?.Result?.Value);

            if (clickableElementId != null)
            {
                var middle      = location.Offset(region.Width / 2, region.Height / 2);
                var isClickable = await VerifyElementClickable(clickableElementId, middle);

                if (!isClickable)
                {
                    return(null);
                }
            }
            return(location);
        }
        public async Task <WebPoint> GetElementClickableLocation(string elementId, CancellationToken cancellationToken = new CancellationToken())
        {
            var tagName = await GetElementTagName(elementId, cancellationToken);

            if (tagName == "area")
            {
                var func =
                    "function (element) {" +
                    "  var map = element.parentElement;" +
                    "  if (map.tagName.toLowerCase() != 'map')" +
                    "    throw new Error('the area is not within a map');" +
                    "  var mapName = map.getAttribute('name');" +
                    "  if (mapName == null)" +
                    "    throw new Error ('area\\'s parent map must have a name');" +
                    "  mapName = '#' + mapName.toLowerCase();" +
                    "  var images = document.getElementsByTagName('img');" +
                    "  for (var i = 0; i < images.length; i++) {" +
                    "    if (images[i].useMap.toLowerCase() == mapName)" +
                    "      return images[i];" +
                    "  }" +
                    "  throw new Error('no img is found for the area');" +
                    "}";
                var frameId = Session == null ? "" : Session.GetCurrentFrameId();
                var res     = await webView.CallFunction(func, $"{{\"{GetElementKey()}\":\"{elementId}\"}}", frameId, true, false);

                return(ResultValueConverter.ToWebPoint(res?.Result?.Value));
            }
            var isDisplayed = await IsElementDisplayed(elementId, cancellationToken);

            if (isDisplayed)
            {
                var rect = await GetElementRegion(elementId, cancellationToken);

                var location = await ScrollElementRegionIntoView(elementId, rect, true, elementId, cancellationToken);

                return(location.Offset(rect.Width / 2, rect.Height / 2));
            }
            return(null);
        }
예제 #3
0
        public async Task <WebPoint> GetElementLocation(string elementId)
        {
            var res = await webView.CallFunction(atoms.GET_LOCATION, $"{{\"{GetElementKey()}\":\"{elementId}\"}}");

            return(ResultValueConverter.ToWebPoint(res?.Result?.Value));
        }
        public async Task <WebPoint> GetElementLocation(string elementId, CancellationToken cancellationToken = default(CancellationToken))
        {
            var res = await _webView.CallFunction(atoms.GET_LOCATION, $"{{\"{Session.GetElementKey()}\":\"{elementId}\"}}", _asyncChromeDriver.Session.GetCurrentFrameId(), cancellationToken : cancellationToken).ConfigureAwait(false);

            return(ResultValueConverter.ToWebPoint(res?.Result?.Value));
        }