Click here to Skip to main content
15,912,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to access to this website : www.wine-searcher.com/wine-valuation-f.lml , and I want to change value of the first textbox and to submit with the button below "cotation" .
how can I do that programmatically with c# ?

I tried this but I get Null Reference Exception

this is my code :

webBrowser1.Navigate("http://www.wine-searcher.com/wine-valuation-f.lml");
webBrowser1.Document.GetElementById("wn1_input").InnerText ="TextToPut";


Thank you in advance for your answer.
Posted
Updated 31-May-14 13:04pm
v2
Comments
CHill60 31-May-14 18:54pm    
???
[no name] 31-May-14 19:44pm    
You need to actually wait until the document loads before trying to do anything with the controls on the page.

1 solution

Your code is just right, but you must handle the DocumentCompleted Event.

see, for example
C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            webBrowser1.Navigate("http://www.wine-searcher.com/wine-valuation-f.lml");

        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser1.Document.GetElementById("wn1_input").InnerText = "TextToPut";
        }
    }

hope it helps :)
 
Share this answer
 
Comments
Youssef Korchi 1-Jun-14 9:37am    
thanks it works ! but my input field still empty. Here is the tag where i want to change the value :

<input class="valftlt" name="wn1" id="wn1_input" type="TEXT">
Octanic 1-Jun-14 9:47am    
Glad to see it worked! Remember you can always try to consume it as a webrequest, passing post parameters with the same name as the "name" attribute with the value you desire. So you don't really need to use webbrowser to do it :)
Youssef Korchi 1-Jun-14 11:43am    
Actually I don't know how to do it with webrequest but it worked ,I forget to add in my Form() :

webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

thanks Luis

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900