saba
saba

Reputation: 107

how to set value of html element in c#

I am developing a project to take data from a website.so I used a webBrowser and set the url to travelchi.ir and I wrote below code

 private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlDocument doc = webBrowser1.Document;
            HtmlElement Source = doc.GetElementById("from");
            HtmlElement Destination = doc.GetElementById("to");
            HtmlElement adultCount = doc.GetElementById("adultCount");
            HtmlElement childCount = doc.GetElementById("childCount");
            HtmlElement infantCount = doc.GetElementById("infantCount");
            var links = webBrowser1.Document.GetElementsByTagName("button");
            var inputs = webBrowser1.Document.GetElementsByTagName("input");
            Source.SetAttribute("value", "شیراز");
            Destination.SetAttribute("value", "تهران");
            adultCount.SetAttribute("value", "1 بزرگسال");
            childCount.SetAttribute("value", "1 کودک");
            infantCount.SetAttribute("value", "0 خردسال");
            foreach (HtmlElement input in inputs)
            {
                if (input.GetAttribute("className") == "form-control")
                {
                    input.SetAttribute("value", "1395/05/14");
                }
            }

            foreach (HtmlElement link in links)
            {
                if (link.GetAttribute("className") == "btn btn-primary")
                {
                    link.InvokeMember("click");
                }
            } 

to getelement and set value to it so at the end I ecounter that this code can not set value please help me to solve it

Upvotes: 1

Views: 4496

Answers (1)

Related Questions