コード例 #1
0
        public async Task <string> GetElementEffectiveStyle(string elementId, string property, CancellationToken cancellationToken = new CancellationToken())
        {
            var res = await WebView.CallFunction(atoms.GET_EFFECTIVE_STYLE, $"{{\"{Session.GetElementKey()}\":\"{elementId}\"}}, \"{property}\"", Session?.GetCurrentFrameId(), true, false, cancellationToken).ConfigureAwait(false);

            var value     = res?.Result?.Value as JToken;
            var exception = ResultValueConverter.ToWebBrowserException(value);

            if (exception != null)
            {
                throw exception;
            }
            return(ResultValueConverter.AsString(res?.Result?.Value));
        }
コード例 #2
0
        public async Task <bool> SetOptionElementSelected(string elementId, bool selected = true, CancellationToken cancellationToken = new CancellationToken())
        {
            var res = await WebView.CallFunction(atoms.CLICK, $"{{\"{Session.GetElementKey()}\":\"{elementId}\"}}, {selected.ToString().ToLower()}", Session?.GetCurrentFrameId(), true, false, cancellationToken).ConfigureAwait(false);

            var value     = res?.Result?.Value as JToken;
            var exception = ResultValueConverter.ToWebBrowserException(value);

            if (exception != null)
            {
                throw exception;
            }
            return(ResultValueConverter.ToBool(res?.Result?.Value));
        }
コード例 #3
0
        public async Task <bool> IsElementEnabled(string elementId, CancellationToken cancellationToken = new CancellationToken())
        {
            var res = await WebView.CallFunction(atoms.IS_ENABLED, $"{{\"{Session.GetElementKey()}\":\"{elementId}\"}}", Session?.GetCurrentFrameId(), true, false, cancellationToken).ConfigureAwait(false);

            var value     = res?.Result?.Value as JToken;
            var exception = ResultValueConverter.ToWebBrowserException(value);

            if (exception != null)
            {
                throw exception;
            }
            return(ResultValueConverter.ToBool(res?.Result?.Value));
        }
コード例 #4
0
        public async Task <string> GetElementTagName(string elementId, CancellationToken cancellationToken = new CancellationToken())
        {
            var func = "function(elem) { return elem.tagName.toLowerCase(); }";
            var res  = await WebView.CallFunction(func, $"{{\"{Session.GetElementKey()}\":\"{elementId}\"}}", Session?.GetCurrentFrameId(), true, false, cancellationToken).ConfigureAwait(false);

            var value     = res?.Result?.Value as JToken;
            var exception = ResultValueConverter.ToWebBrowserException(value);

            if (exception != null)
            {
                throw exception;
            }
            return(ResultValueConverter.AsString(res?.Result?.Value));
        }
コード例 #5
0
        public async Task <bool> IsOptionElementTogglable(string elementId, CancellationToken cancellationToken = new CancellationToken())
        {
            //var expression = $"({is_option_element_toggleable.JsSource}).apply(null, {{\"{Session.GetElementKey()}\":\"{elementId}\"}})";
            //var frameId = Session == null ? "" : Session.GetCurrentFrameId();
            //var res = await webView.EvaluateScript(expression, frameId, true, cancellationToken);
            var res = await WebView.CallFunction(is_option_element_toggleable.JsSource, $"{{\"{Session.GetElementKey()}\":\"{elementId}\"}}", Session?.GetCurrentFrameId(), true, false, cancellationToken).ConfigureAwait(false);

            var value     = res?.Result?.Value as JToken;
            var exception = ResultValueConverter.ToWebBrowserException(value);

            if (exception != null)
            {
                throw exception;
            }
            return(ResultValueConverter.ToBool(res?.Result?.Value));
        }
コード例 #6
0
        public async Task <JToken> FindElements(string strategy, string expr, string startNode = null, CancellationToken cancellationToken = new CancellationToken())
        {
            var func    = atoms.FIND_ELEMENTS;
            var frameId = _session == null ? "" : _session.GetCurrentFrameId();

            expr = Regex.Replace(expr, @"(['""\\#.:;,!?+<>=~*^$|%&@`{}\-/\[\]\(\)])", @"\$1");
            var args = $"{{\"{strategy}\":\"{expr}\"}}";

            if (startNode != null)
            {
                args += $", {{\"{_session.GetElementKey()}\":\"{startNode}\"}}";
            }
            var res = await _webView.CallFunction(func, args, frameId, true, false, cancellationToken).ConfigureAwait(false);

            var value     = res?.Result?.Value as JToken;
            var exception = ResultValueConverter.ToWebBrowserException(value);

            if (exception != null)
            {
                throw exception;
            }
            return(value?["value"]);
        }