Irfan Faruki

Hi Everyone
After creating simple address book application. I am now trying my hands on web browser functionality. What i am trying to do is write a small program with a webbrowser and button to fill details in the form. At the moment i am function webBrowser.document.innerhtml to get form details and then fill the details in. But what i want to do is dynamically gather all the input element on that particular web page. Does anyone know how do i go about doing this

Regards
Irfan





Re: Visual C# Express Edition How to fill a form in web browser - Another question by a newbie

ahmedilyas

what do you mean by dynamically gathering all the input element

Are you trying to get the controls on the page and obtain their content If so, you need to find the control in the document (GetElementById)

Example:

HtmlElement myElement = this.webBrowser.Document.GetElementById("controlID");

if (myElement != null)

{

//get innertext of myElement

}

is this what you are after

Alternatively, you could get ALL the HtmlElement controls using the Document.All property and iterate through it to get the element you like, if this is what you want to do.






Re: Visual C# Express Edition How to fill a form in web browser - Another question by a newbie

Irfan Faruki

Hi Ahmed
Sorry i did not make the question clear enough. Please have a look at the example below

Lets say there is a web page that has these input fields on it that you can complete

(checkbox ) Mr, Mrs
(inputText box) First Name
(inputText box) Last Name
(inputText box) Address
(inputText box) City

what i want to do is get all the elements on the webpage that have input tag and my problem is that i dont know how to do that

Irfan






Re: Visual C# Express Edition How to fill a form in web browser - Another question by a newbie

ahmedilyas

There isn't a way to do this unfortunately - not entirely

You could check to see what the Element tag type is, if its "Input" then it generally is an input type (text) but specifically depending on how the page has been built, it needs to be in the form of:

Code Snippet
<input type="text" id="someID">

then do a search by elementID of "someID" and check its input type

The best way yet...is this:

Code Snippet

HtmlElement textBoxElement = this.webBrowser.Document.GetElementById("inputId");

if (textBoxElement != null)

{

if (textBoxElement.GetAttribute("type") == "text")

{

//input type is a textbox!

}

}

The above checks to see what type of input the element is. If its text, then you are in luck.






Re: Visual C# Express Edition How to fill a form in web browser - Another question by a newbie

Irfan Faruki

Hi
Thanks for the answer I tried using the code but i am getting following error


Cannot convert type 'System.Windows.Forms.HtmlElementCollection' to 'mshtml.HTMLElementCollection'


I am also trying to see if i can use the statement below but i still get the same error

HTMLElementCollection inputElements = (HTMLElementCollection)webBrowser.Document.GetElementsByTagName("input");

Thanks
Irfan





Re: Visual C# Express Edition How to fill a form in web browser - Another question by a newbie

ahmedilyas

what type of control are you using

is it the .NET Framework webbrowser control






Re: Visual C# Express Edition How to fill a form in web browser - Another question by a newbie

Andreas Johansson

Irfan Faruki wrote:
Hi
HTMLElementCollection inputElements = (HTMLElementCollection)webBrowser.Document.GetElementsByTagName("input");

This is almost correct but GetElementsByTagName() do note return a HTMLElementCollection but a HtmlElementCollection, not the difference in upper/lower case.

Code Snippet

HtmlElementCollection inputElements = webBrowser.Document.GetElementsByTagName("input");






Re: Visual C# Express Edition How to fill a form in web browser - Another question by a newbie

Irfan Faruki

@ahmedilyas..

Yes its a webbrowser control

@Andreas

Thanks for pointing that out. I will give it a try and see how it goes

THanks
Irfan