Hello I am working on autologin for page, I am using WebBrowser control. I have this code which sets the value of DOM elements with the values found in my form controls, TextBox1 and TextBox2:
WebBrowser1.Document.GetElementById("email").SetAttribute("value", TextBox1.Text.ToString())
WebBrowser1.Document.GetElementById("password").SetAttribute("value", TextBox2.Text.ToString())
It fill the elements with text from TextBoxes, but if i hit "Log IN" button, it says that user does not exist or the password is bad.
These 2 inputs I'm trying to fill :
<input type="email" name="email" tabindex="0" value="">
<input type="password" name="password" tabindex="0" value="">
I also tried to load the values using a RichTextBox control and they are same so I don't really know where is the problem. If I try to log in manually, all works fine.
The DOM elements do not have an ID attribute, but they do have name attributes set. This makes it a bit more difficult in that you will need to query the document's elements a bit differently, but it is still achievable. Try the following:
What this code does is it tries to get the first input element named email as well as the first input element named password. If the element was found, then it sets the attribute to the respective TextBox text.
You'll noticed that I removed the
.ToString()from the Text property. This is because the Text property returns a String and so what you were doing was converting a String... into a String.Update
My apologies, I did not realize that the HtmlElementCollection doesn't support FirstOrDefault. You'll need to change the code slightly to: