Пример #1
0
        public void Submit()
        {
            var document = _form.SubmitAsync().Result;

            Console.WriteLine(document.ToHtml());
            Console.ReadLine();
        }
Пример #2
0
        public async Task Test1Async()
        {
            var context       = BrowsingContext.New(Configuration.Default.WithDefaultLoader());
            var queryDocument = await context.OpenAsync("https://google.com");

            IHtmlFormElement form = queryDocument.QuerySelector("form") as IHtmlFormElement;
            var resultDocument    = await form.SubmitAsync(new { q = "anglesharp" });

            Assert.True(resultDocument != null);
            //
        }
        public async Task Warning_WhenNoText(string url)
        {
            //Arrange
            HttpResponseMessage page = await _client.GetAsync(url);

            IHtmlDocument document = await HtmlHelpers.GetDocumentAsync(page);

            IHtmlFormElement  form         = (IHtmlFormElement)document.Body.SelectSingleNode(@".//form[@id=""messageForm""]");
            IHtmlInputElement textField    = (IHtmlInputElement)document.Body.SelectSingleNode(@".//input[@id=""textInput""]");
            IHtmlInputElement submitButton = (IHtmlInputElement)document.Body.SelectSingleNode(@".//input[@id=""submitForNewMessage""]");

            //Act


            if (form != null)
            {
                textField.Value = "aaaaaaaaaaaaaaaaaaaaaaaaa";
                await form.SubmitAsync(submitButton);
            }
            //Arrange

            Assert.Equal(HttpStatusCode.OK, page.StatusCode);
        }
Пример #4
0
 /// <summary>
 /// Submits the given form by using the dictionary which contains name
 /// value pairs of input fields to submit.
 /// </summary>
 /// <param name="form">The form to submit.</param>
 /// <param name="fields">The fields to use as values.</param>
 /// <param name="createMissing">
 /// What to do if some field(s) have not been found in the form. If
 /// true, then new input will be created. Otherwise, an exception will
 /// be thrown.
 /// </param>
 /// <returns>The task eventually resulting in the response.</returns>
 public static Task <IDocument> SubmitAsync(this IHtmlFormElement form, IDictionary <String, String> fields, Boolean createMissing = false)
 {
     form.SetValues(fields, createMissing);
     return(form.SubmitAsync());
 }
Пример #5
0
 /// <summary>
 /// Submits the given form by decomposing the object into a dictionary
 /// that contains its properties as name value pairs.
 /// </summary>
 /// <param name="form">The form to submit.</param>
 /// <param name="fields">The fields to use as values.</param>
 /// <returns>The task eventually resulting in the response.</returns>
 public static Task <IDocument> SubmitAsync(this IHtmlFormElement form, Object fields)
 {
     return(form.SubmitAsync(fields.ToDictionary()));
 }
Пример #6
0
 /// <summary>
 /// Submits the given form by using the dictionary which contains name
 /// value pairs of input fields to submit.
 /// </summary>
 /// <param name="form">The form to submit.</param>
 /// <param name="fields">The fields to use as values.</param>
 /// <param name="createInputIfNotFound">
 /// What to do if some field(s) have not been found in the form. If
 /// true, then new input will be created. Otherwise, an exception will
 /// be thrown.
 /// </param>
 /// <returns>The task eventually resulting in the response.</returns>
 public static Task <IDocument> SubmitAsync(this IHtmlFormElement form, IDictionary <String, String> fields, Boolean createInputIfNotFound = false)
 {
     form.SetFieldValues(fields, createInputIfNotFound);
     return(form.SubmitAsync());
 }