public void Submit() { var document = _form.SubmitAsync().Result; Console.WriteLine(document.ToHtml()); Console.ReadLine(); }
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); }
/// <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()); }
/// <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())); }
/// <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()); }