title: Automation using mshtml dll c# for webforms getelementbytagname doesnt work
body: <p>I am trying to automate a flow of logging in to a third party website and fetching data using C#, mshtml dll and SHDocVw.dll in webforms.</p>
  
  <p>I am able to login, Fill textboxes, click on button, navigate to new page. I am using getelementbyid method to get the details of the above controls to perform action.</p>
  
  <p>On using getelementbytagname, It's not fetching any data.</p>
  
  <p>Elements, elements1, elements 2 comes as black. No values are populated, even though html has these tags and tag ids.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>SHDocVw.InternetExplorer ie = new
             SHDocVw.InternetExplorerClass();
  SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)ie;
  object nullObject = null;
  wb.Visible = true;
  wb.Navigate("url", ref nullObject, ref nullObject, ref nullObject, ref 
  nullObject);           
  while (wb.Busy) { Thread.Sleep(100); }           
  HTMLDocument document = ((HTMLDocument)wb.Document);
  IHTMLElement element = document.getElementById("username");
  HTMLInputElementClass email = (HTMLInputElementClass)element;
  email.value = "abc";
  email = null;
  element = document.getElementById("password");
  HTMLInputElementClass pass = (HTMLInputElementClass)element;
  pass.value = "Admin123";
  pass = null;
  element = document.getElementById("btnSubmit_6");
  HTMLInputElementClass subm = (HTMLInputElementClass)element;
  subm.click();
  subm = null;
  wb.Navigate("url1");
  wb.Navigate("url2");
  element = document.getElementById("action_46");
  HTMLInputElementClass Cont = (HTMLInputElementClass)element;
  Cont.click();
  Cont = null;
  wb.Navigate("url3");
  element = document.getElementById("username_53");
  HTMLInputElementClass login = (HTMLInputElementClass)element;
  login.value = "abc";
  login = null;
  element = document.getElementById("password_50");
  HTMLInputElementClass passwd = (HTMLInputElementClass)element;
  passwd.value = "abcd";
  passwd = null;
  element = document.getElementById("userDomain_2");
  HTMLInputElementClass domain = (HTMLInputElementClass)element;
  domain.value = "abc";
  domain = null;
  element = document.getElementById("action_49");
  HTMLInputElementClass submt = (HTMLInputElementClass)element;
  submt.click();
  submt = null;
  wb.Navigate("url4");
  //Select Node
  IHTMLElementCollection elements = document.getElementsByTagName("div");
  IHTMLElementCollection elements1 =                     document.getElementsByTagName("//div[@id='postB']");
  IHTMLElementCollection elements2 = (IHTMLElementCollection)document.getElementById("postB");
  </code></pre>
  
  <blockquote>
    <p>Please find HTML code which I am trying to retrieve. There are many tags with id postA. I need to get all the tags and search for a text in the content of the tag and display. Or is there any way I can search for a particular text in entire html page?</p>
  </blockquote>
  
  <pre><code>&lt;DIV id="postA"&gt;[Aug 01 09h43:20.934] - &lt;a href="javascript://" 
  onClick="toggle(this)"&gt;Message from 18998652 [161.126.169.35,3878]&lt;/a&gt;
  &lt;DIV id="postB"&gt;&lt;UL&gt;
  &lt;PRE format=object&gt;1420:
  [LLVAR  n    ..19 019] 002 [7077186160620160159] 
  [Fixed  n       6 006] 003 [000000] 
  [None   n         012] 004 [000000160000] 
  [Fixed  n       6 006] 011 [040174] 
  [Fixed  n      12 012] 012 [170801114140] 
  [Fixed  n       4 004] 014 [1906] 
  [Fixed  n       3 003] 024 [400] 
  [Fixed  n       4 004] 025 [4000] 
  [Fixed  ans     6 006] 038 [477762] 
  [Fixed  n       3 003] 039 [000] 
  [Fixed  ans     8 008] 041 [18998652] 
  [Fixed  ans    15 015] 042 [189986         ] 
  [LLVAR  ans  ..99 040] 043 [Shell\NL Unmanned 80998\Netherlands  \NL] 
  [LLLVAR b   ..999   041]    048
  [Fixed  a       2 002] 003 [EN] 
  [Fixed  n      10 010] 004 [0000000231] 
  [Fixed  ans     2 002] 014 [23] 
  &lt;/PRE format=object&gt;&lt;DIV  id="postC"&gt;&lt;a href="javascript://" 
  onClick="toggle(this)"&gt;binary data&lt;/a&gt;
  &lt;DIV id="postD"&gt;&lt;UL&gt;&lt;PRE format=object&gt;
  0000(0000)  31 34 32 30 70 34 01 80  06 e1 89 01 31 39 37 30   
  1420p4......1970
  &lt;/PRE format=object&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;
  &lt;/UL&gt;&lt;HR&gt;&lt;/DIV&gt;
  &lt;/DIV&gt;
  &lt;!--EOM--&gt;
  &lt;DIV id="postA"&gt;[Aug 01 09h43:20.953] - &lt;a href="javascript://" 
  onClick="toggle(this)"&gt;&amp;lt;0420&amp;gt; Message to Transaction Manager 
  [10.104.15.12,4008]&lt;/a&gt;
  &lt;DIV id="postB"&gt;&lt;UL&gt;
  &lt;PRE format=object&gt;0420:
  [LLVAR  n    ..19 019] 002 [7077186160620160159] 
  [Fixed  n       6 006] 003 [000000] 
  [None   n         012] 004 [000000160000] 
  [Fixed  n      10 010] 007 [0801094320] 
  [Fixed  n       6 006] 011 [040174] 
  [Fixed  n       6 006] 012 [114140] 
  [Fixed  n       4 004] 013 [0801] 
  [Fixed  n       4 004] 014 [1906] 
  [Fixed  n       3 003] 022 [000] 
  [Fixed  n       2 002] 025 [00] 
  [Fixed  n       2 002] 026 [12] 
  [LLVAR  n    ..11 003] 032 [528] 
  [Fixed  ans     6 006] 038 [477762] 
  [Fixed  ans     8 008] 041 [18998652] 
  [Fixed  ans    15 015] 042 [NL9986000000000] 
  [Fixed  ans    40 040] 043 [Shell NL Unmanned 80998Netherlands  NLNL] 
  [Fixed  a/n     3 003] 049 [978] 
  [LLLVAR n       4 004] 056 [4000] 
  [LLLVAR ans ..500 266] 059 [0000000231                         
  &lt;/PRE format=object&gt;&lt;DIV  id="postC"&gt;&lt;a href="javascript://" 
  onClick="toggle(this)"&gt;binary data&lt;/a&gt;
  </code></pre>