0

I'm creating an application and I have made a login form which should accept the user's account login information, login to a specific website with those, and show the website in the in-app webbrowser. I know how to do so, but only if the website provides me with the "id's" of each element. The website I'm interested in, only shows class, name, size and type of the username and password elements and only class, value and type of the "login" button. Is there a way to find the id's of these elements or else how can I use the existing information instead ?

Below is a picture for each elements' provided information:

Username:

Password:

login btn info:

Here is the code I have to get elements by ID:

                webBrowser1.Document.GetElementById("user").SetAttribute("value", bTextBox1.Text);
                webBrowser1.Document.GetElementById("passwrd").SetAttribute("value", bTextBox2.Text);
                webBrowser1.Document.GetElementById("button_submit").InvokeMember("click");

I will really appreciate your help but please keep the coding as simple as possible :)

EDIT: I tried this:

webBrowser1.Document.GetElementsByTagName("input_text").GetElementsByName("user")[0].SetAttribute("input", bTextBox1.Text);

But it still didn't work

Bill M.
  • 151
  • 4
  • 15
  • The submit button does not have a name, but I guess the form element has. – NineBerry Jun 03 '18 at 11:53
  • Id is not a constant tag in every login form class is enough so the right question should be how to get the value of an element by tag name – Ahmed Soliman Jun 03 '18 at 11:55
  • Thank you ahmed.soli , I guess that is my problem, as you described. However the login button does not have a name 'variable'; only has class, value and type – Bill M. Jun 03 '18 at 12:01
  • NineBerry, rene The post has been edited. I tried this: webBrowser1.Document.GetElementsByTagName("input_text").GetElementsByName("user")[0].SetAttribute("input", bTextBox1.Text); as suggested by the first related post, but it does not work – Bill M. Jun 03 '18 at 12:16
  • You shouldn't do it this way. Create a colletion of the `INPUT` elements which refer to the same `FORM` (there might be more then one Form in a page) using `GetElementsByTagName()` (the tag name is "Input"). Use [`HtmlElement.GetAttribute`](https://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.getattribute(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1) to identify the correct element (the attribute "type" can be useful here). After having set the new values, Invoke a `click` action on the element with attribute type `submit`. – Jimi Jun 03 '18 at 14:19
  • Jimi, is it possible to provide me with an example code? – Bill M. Jun 03 '18 at 16:00
  • As you can see, your question has been marked as a Duplicate and cannot be answered anymore. Try to put into code the hints I gave you. If you can't get it to work for some reason, post another question showing what you tried and explaining what failed. – Jimi Jun 03 '18 at 21:00

0 Answers0