WebBrowser SetAttribute does not work (Password field)

tried to write a program that automatically writes me to a webbrowser in c #. This is the code I'm currently using for this purpose:

HtmlElementCollection pageTextElements = loginBrowser.Document.GetElementsByTagName("input");
        foreach (HtmlElement element in pageTextElements)
        {
            if (element.Name.Equals("username"))
                element.SetAttribute("value", this.UserName);
            if (element.Name.Equals("password"))
                element.SetAttribute("value", this.Password);
        }

Does it populate a username but not a password? ): Google, but there are only a few people who started a topic that no one ever answered. /:

hope someone can help me. this is the source in the password field:

<input type="password" value="" maxlength="50" size="25" name="password" class="bginput">
+3
source share
3 answers

You need to wait until the document is updated. DocumentCompletedevent method.

, , Panel WebBrowser . 3 TextBoxes, a Button TextBox. OnClick :

webBrowser1.Document.GetElementById(this.textBox1.Text).SetAttribute(this.textBox2.Text, this.textBox3.Text);
this.textBox4.Text = webBrowser1.Document.GetElementById(this.textBox1.Text).GetAttribute(this.textBox2.Text);

, Password .

+3

, setAttribute() username DocumentCompleted(), . :

HtmlElementCollection inputs = doc.GetElementsByTagName("input");
HtmlElement usr = inputs.GetElementsByName("username")[0];
usr.setAttribute("value", strUsername);

HtmlElement pwd = inputs.GetElementsByName("password")[0];
pwd.GotFocus += new HtmlElementEventHandler(pwd_GotFocus);
pwd.Focus();

onFocus:

void pwd_GotFocus(object sender, HtmlElementEventArgs e)
{
    HtmlElement pwd = (HtmlElement)sender;
    pwd.SetAttribute("value", strPassword);
}

, , - . , , , . , WebBrowser, DocumentText , html DocumentText WebBrowser, .

, -

+2

innerText , (vb.net):

Dim txtPassword As HtmlElement = browser.Document.GetElementById("ctl00_ContentPlaceHolder1_txtPassword")

txtPassword.InnerText = "123456"
+1

Source: https://habr.com/ru/post/1776747/


All Articles