Reputation: 74
I'm trying to open a web page in my webbrowser control and change the value of input fields. Works good when I'm doing it like this webBrowser.Document.GetElementById("Email").SetAttribute("value", "[email protected]");
on a page with defined element Ids, but now I've encountered a page where the html/javascript looks something like this:
<input id="${Id}" name="${Id}" type="text" class="text field" value="${Value}" title="${ToolTip}" />
So my question is how do I find this specific input field from the C# code?
Upvotes: 1
Views: 7601
Reputation: 191
You can find element by class name by using the following function,
public static HtmlElement GetHTMLElementByClass(HtmlDocument document, String className)
{
foreach (HtmlElement element in document.All)
{
if (element.GetAttribute("className") == className)
{
return element;
}
}
}
Upvotes: 1
Reputation: 3891
Try This
This is a C# coding
HtmlElement Elem = AutomationWebBrowser.Document.GetElementById('<your element ID>');
Elem.SetAttribute("value", '<value to assign in input control>');
Also you can use variables inside the GetElementById and SetAttribute function
Upvotes: 3