-1

There is a Page, I want to get it's body for reading input areas, and changing their values by GetAttribute and SetAttribute in C#. This is no problem to do it but,

There is nothing returns (I mean empty string), when I call the body via:

webBrowser1.Document.Body.InnerText 

or,

webBrowser1.Document.Body.InnerHtml

That's why I can't acces any input field. I see The Web Page in webbrowser component, But Neither InnerText nor InnerHtml return. It's a saved Bank weppage running on local.

So How can I read body, for running SetAttribute or GetAttribute or InvokeMember something else?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Ali CAKIL
  • 383
  • 5
  • 21
  • 2
    Do you wait until the page is completely loaded? http://stackoverflow.com/questions/20957182/load-url-from-txt-file-and-load-the-url-in-browser-synchronous-webclient-httpreq – L.B Mar 01 '14 at 19:11
  • When do you call webBrowser1.Document.Body.InnerText. Immediate after loading page in webbrowser control? – Nps Mar 01 '14 at 19:14
  • Yeah completely loaded.How I dont know but Problem solved. Perhabs I missed something. I get only Frame tags. Then I tryed to acces into each frames by code: webBrowser1.Document.Window.Frames[i].Document.Body.InnerHtml And that works – Ali CAKIL Mar 01 '14 at 19:26

1 Answers1

-2

You need to get the input element then to get or set the text :

HtmlElementCollection elements = currentBrowser.Document.GetElementsByTagName("INPUT");
     foreach (HtmlElement element in elements)
        {
           //to get the text use :  string value = element.GetAttribute("value");
           //to set the text use :  elemet.InnerText = "something";

        }

but don't forget that by the code above you get all the input elements , to search for a specific element you can check its id or name as in the webpage : for example :

 if (element.Name.ToLower().Contains("email"))
         //do work
Karam Najjar
  • 527
  • 5
  • 21