Sunday, December 16, 2012

WPF Webbrowser loop through html elements and submit

A question was raised on vbforums on how to invoke click a button using WPF webbrowser control. This sample loads google.com page and writes a sample text on the textbox and then invoking the click button.
Code:
 HTMLDocument document = (HTMLDocument)wbGetHost.Document;  
       foreach (IHTMLElement myelem in document.getElementsByTagName("input"))  
       {  
         if (myelem.id != null)  
         {  
           if (myelem.id.Equals("lst-ib") && myelem.className.Equals("lst lst-tbb") && !document.documentElement.innerHTML.ToLower().Contains("wikipedia"))  
           {  
             HTMLInputElement el = myelem as HTMLInputElement;  
             el.value = "Bill Gates";  
             HTMLInputElement searchButton = (HTMLInputElement)document.all.item("btnK", 0);  
             searchButton.click();  
             break;  
           }  
         }  
       } 
Greg

0 comments:

Post a Comment