Пример #1
0
        /// <summary>
        /// Builds the get location.
        /// </summary>
        /// <param name="sourceButton">
        /// The source button.
        /// </param>
        /// <returns>
        /// A <see cref="Uri"/> value.
        /// </returns>
        public virtual Uri BuildGetLocation(HtmlButton sourceButton)
        {
            var target      = ActionTarget;
            var queryString = string.Empty;
            var postData    = BuildPostParameters(sourceButton);

            queryString = postData.Aggregate(
                queryString,
                (x, y) => x + "&" + HttpUtility.UrlEncode(y.Name) + "=" + HttpUtility.UrlEncode(y.Value));

            if (string.IsNullOrWhiteSpace(queryString))
            {
                return(target);
            }

            if (string.IsNullOrWhiteSpace(target.Query))
            {
                // Strip the leading &
                queryString = queryString.Substring(1);

                queryString = "?" + queryString;
            }

            var location = new Uri(target + queryString);

            return(location);
        }
Пример #2
0
        /// <summary>
        /// Submits the specified form and returns the response from the server.
        /// </summary>
        /// <typeparam name="T">
        /// The type of page returned.
        /// </typeparam>
        /// <param name="sourceButton">
        /// The button that invoked the submit action.
        /// </param>
        /// <returns>
        /// A <typeparamref name="T"/> value.
        /// </returns>
        public T Submit <T>(HtmlButton sourceButton) where T : IPage, new()
        {
            if (IsPostForm)
            {
                var parameters = BuildPostParameters(sourceButton);

                return(Page.Browser.PostTo <T>(parameters, ActionTarget, HttpStatusCode.OK));
            }

            var location = BuildGetLocation(sourceButton);

            return(Page.Browser.GoTo <T>(location));
        }
Пример #3
0
        /// <summary>
        /// Submits the specified form and returns the response from the server.
        /// </summary>
        /// <param name="sourceButton">
        /// The button that invoked the submit action.
        /// </param>
        /// <returns>
        /// A <see cref="IPage"/> value.
        /// </returns>
        public dynamic Submit(HtmlButton sourceButton)
        {
            if (IsPostForm)
            {
                var parameters = BuildPostParameters(sourceButton);

                return(Page.Browser.PostTo(parameters, ActionTarget, HttpStatusCode.OK));
            }

            var location = BuildGetLocation(sourceButton);

            return(Page.Browser.GoTo(location));
        }
Пример #4
0
        public virtual IEnumerable <PostEntry> BuildPostParameters(HtmlButton sourceButton)
        {
            // Find all the form elements that are not buttons
            var availableElements = Find <HtmlFormElement>().All().Where(x => x is HtmlButton == false).ToList();

            if (sourceButton != null && string.IsNullOrWhiteSpace(sourceButton.Name) == false)
            {
                // The source button can be identified to the server so it must be added to the post data
                availableElements.Add(sourceButton);
            }

            var postData = availableElements.SelectMany(x => x.BuildPostData());

            return(postData);
        }