Reputation: 107
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
Reputation: 853
Method is getElementById and not GetElementById.
Same follows for getElementsByTagName and setAttribute
Reference :-
Upvotes: 1