These two lines in your code are redundant and are probably not what you intended...
HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("input");
HtmlElement el = this.webBrowser1.Document.GetElementsByTagName("input");
The second line above is doing exactly what the first is doing but putting the result in a different object (of the wrong type by the way, GetElementsByTagName() returns a collection of elements not a single HtmlElement).
You want to get a collection of the input elements, like the first line does. But then you want to work with the collection to get the specific input item from the collection.
You have multiple options to do this...
Option #1 - This option is closet to what you are trying in your code. But it assumes that we always want the first input element
HtmlElementCollection elc = webBrowser1.Document.GetElementsByTagName("input");
if (elc != null && elc.Count > 0)
{
HtmlElement el = elc[0];
if (el.GetAttribute("value").Contains("Book it") == true)
{
MessageBox.Show("find");
}
else
{
MessageBox.Show("no");
}
}
Option #2 - This option uses a loop to check all input controls in the collection and assumes the value we are looking for can be part of one or more of the input elements
HtmlElementCollection elc = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement el in elc)
{
if (el.GetAttribute("value").Contains("Book it") == true)
{
MessageBox.Show("find");
}
}
Option #3 - This option uses LINQ to condense the code and is essentially doing what option #2 does but with less code.
HtmlElementCollection elc = webBrowser1.Document.GetElementsByTagName("input");
HtmlElement el = (from HtmlElement eli in elc
where eli.GetAttribute("value") == "Book it"
select eli).FirstOrDefault();
if (el != null)
{
MessageBox.Show("find");
}
Hope this helps.