Exemple #1
0
        public Task SetValueAsync(string value)
        {
            var script = $"var obj = {JavaScriptSnippets.GetFindScript(_xpath)}[0];" +
                         $"obj.value = '{value}';";

            return(ExecuteScriptAsync(script));
        }
Exemple #2
0
        public async Task FindAsync()
        {
            await IncludeJQueryToPageAsync().ConfigureAwait(false);

            var script = JavaScriptSnippets.GetFindScript(_xpath) + ".length;";

            await ExecuteScriptAsync(script, Continuation).ConfigureAwait(false);

            void Continuation(Task <JavascriptResponse> t)
            {
                if (t.IsFaulted)
                {
                    return;
                }
                var response = t.Result;

                if (response.Success && int.TryParse(response.Result?.ToString(), out int count) && count > 0)
                {
                    IsNull = false;
                }
                else
                {
                    IsNull = true;
                }
            }
        }
Exemple #3
0
        public Task SetAttributeAsync(string attrName, string attrValue)
        {
            if (attrName.ToLower() == "value")
            {
                return(SetValueAsync(attrValue));
            }

            var script = $"var obj = {JavaScriptSnippets.GetFindScript(_xpath)}[0];" +
                         $"obj.setAttribute('{attrName}','{attrValue}');";

            return(ExecuteScriptAsync(script));
        }
Exemple #4
0
        public async Task <string> GetValueAsync()
        {
            var    script = $"{JavaScriptSnippets.GetFindScript(_xpath)}[0].value;";
            string result = null;

            await ExecuteScriptAsync(script, Continuation).ConfigureAwait(false);

            return(result);

            void Continuation(Task <JavascriptResponse> t)
            {
                if (t.IsFaulted)
                {
                    return;
                }

                var response = t.Result;

                result = response.Result?.ToString();
            }
        }
Exemple #5
0
        public async Task <string> GetAttributeAsync(string attrName)
        {
            var script = $"var obj = {JavaScriptSnippets.GetFindScript(_xpath)}[0];" +
                         $"obj.getAttribute('{attrName}');";

            string result = null;

            await ExecuteScriptAsync(script, Continuation).ConfigureAwait(false);

            return(result);

            void Continuation(Task <JavascriptResponse> t)
            {
                if (t.IsFaulted)
                {
                    return;
                }

                var response = t.Result;

                result = response.Result?.ToString();
            }
        }
Exemple #6
0
        public async Task <List <IWebElement> > FindChildrenByXPathAsync(string xpath)
        {
            var parentXpath = _xpath;
            var childXpath  = parentXpath + xpath;

            await IncludeJQueryToPageAsync().ConfigureAwait(false);

            var script = JavaScriptSnippets.GetFindScript(childXpath) + ".length";

            int childrenCount = 0;

            await ExecuteScriptAsync(script, GetChildrenCountCallback).ConfigureAwait(false);

            var children = new List <IWebElement>();
            var tasks    = new List <Task>();

            for (int i = 1; i <= childrenCount; i++)
            {
                var child = new WebElement(_browser, $"({childXpath})[{i}]");
                tasks.Add(child.FindAsync());
                children.Add(child);
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);

            return(children);

            void GetChildrenCountCallback(Task <JavascriptResponse> task)
            {
                if (!task.IsFaulted)
                {
                    var response = task.Result;
                    int.TryParse(response.Result?.ToString(), out int count);
                    childrenCount = count;
                }
            }
        }
Exemple #7
0
        public Task ClickAsync()
        {
            var script = "var obj = " + JavaScriptSnippets.GetFindScript(_xpath) + "; obj.click()";

            return(ExecuteScriptAsync(script));
        }
Exemple #8
0
        public Task ScrollIntoViewAsync()
        {
            var script = $"{JavaScriptSnippets.GetFindScript(_xpath)}[0].scrollIntoView();";

            return(ExecuteScriptAsync(script));
        }
Exemple #9
0
        public Task RiseEventAsync(string eventName)
        {
            var script = $"var obj = {JavaScriptSnippets.GetFindScript(_xpath)}[0]; $(obj).trigger('{eventName}');";

            return(ExecuteScriptAsync(script));
        }