Reputation: 17
I am currently using a WebBrowser function in a c# application to automate a login and get information. The problem is when I set a textbox's value by ID, it does not work, it remains as it was (I checked by getting the console to write its value). Here is my code
br.Document.GetElementById("username").SetAttribute("Value", username);
br.Document.GetElementById("password").SetAttribute("Value", password);
br.Document.GetElementById("LoginBtn").InvokeMember("click");
//authcode
Thread.Sleep(5000);
Console.WriteLine(br.Document.GetElementById("username").InnerText) // This does not retrieve the data.
Any and all help is appreciated.
Upvotes: 0
Views: 230
Reputation: 3785
You are setting the Value
attribute, then checking the InnerText
of the tag. Assuming "username" is an input field, it won't have any inner text. You need to check the value of the Value
attribute.
Console.WriteLine(br.Document.GetElementById("username").GetAttribute("Value");
Upvotes: 1