Document structure
"Form0" - Form
- - "panel2" - Panel
- - - "Frm5UC" - Custom item
- - - - "webBrowser1" - Browser
Application logic:
- go to the page in "webBrowser1";
- enter login;
- enter the password;
- click the "Login" button.
If I execute the logic through the code (this is the "Method_0 ()" method), the form does not have time to load in the "Authorization ()" method. I get "webBrowser1.Document = null", error "Object link does not indicate an object instance."
If I do everything through the interface, then everything works.
How to make the logic run programmatically?
- private void Frm5UC_Load(object sender, EventArgs e)
- {
- webBrowser1.Visible = true;
-
-
- Method_0();
- }
-
-
-
- #region *** TESTS ***
- public void Method_0()
- {
- Method_1();
- Method_2();
- }
-
- public void Method_1()
- {
- textBox2.Text = "_domain_com";
- textBox1.Text = @"domain_com/login/";
-
- button1.PerformClick();
- }
-
- public void Method_2()
- {
- Authorization();
- }
- #endregion *** TESTS ***
-
-
- private void button1_Click(object sender, EventArgs e)
- {
- webBrowser1.Navigate(textBox1.Text);
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- Authorization();
- }
-
- public void Authorization()
- {
- foreach (HtmlElement he in webBrowser1.Document.GetElementsByTagName("input"))
- {
- if (he.GetAttribute("name") == "login[login]")
- {
- he.SetAttribute("value", "login798");
- }
- }
-
-
-
- }