2

I am trying to sign in Habr.com with AngleSharp. I can fill e-mail and password fields, but don't know how to submit the form. If you know any other ways, could you share them, please?

string pathPageLogin = "https://account.habr.com/login/?state=43fb94b4773d9f8940cc47fd59b79b5c&consumer=habr&hl=ru_RU";
var config = Configuration.Default.WithDefaultLoader().WithDefaultCookies();
IBrowsingContext browsingContext = BrowsingContext.New(config);
await browsingContext.OpenAsync(pathPageLogin);
browsingContext.Active.QuerySelector<IHtmlInputElement>("#email_field").Value = "***";
browsingContext.Active.QuerySelector<IHtmlInputElement>("#password_field").Value = "***";
browsingContext.Active.QuerySelector<IHtmlInputElement>("#login_form > fieldset > div.form__buttons.s-buttons > button").DoClick();

html:

 <div class="form__field s-field">
 <label for="email_field" class="form__field-label">E-mail</label>
 <input type="email" class="form__field-input" value="" name="email" data-required="true" id="email_field" data-validate_url="/ajax/validate/email/" />
 </div>
 <div class="form__field s-field">
 <label for="password_field" class="form__field-label">Пароль</label>
 <input type="password" class="form__field-input" value="" data-required="true" name="password" id="password_field" />
 </div>
...
<div class="form__buttons s-buttons">
 <button type="submit" name="go" class="button button_wide button_primary">
 Войти
 </button>
asked Aug 10, 2022 at 17:19

1 Answer 1

1

According to the documentation you can submit the form with SubmitAsync on the form element:

var form = queryDocument.QuerySelector<IHtmlFormElement>("#login_form");
var resultDocument = await form.SubmitAsync();
answered Aug 10, 2022 at 20:50
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.