How To Get Html Textbox Value?
I am trying to get values of few textboxes on a website in a C# WinForms app. It is input type text, set to readonly, but when I try to read it in my app using string price = webBr
Solution 1:
Unfortunately the value from the text box cannot be retrieved using GetAttribute
.
You can use the following code to retrieve the value:
dynamic elePrice = webBrowser.Document.GetElementById("price").DomElement;
string sValue = elePrice.value;
If you are not able to use dynamic
(i.e. .NET 4+) then you must reference the 'Microsoft HTML Object Library' from the COM tab in Visual Studio and use the following:
mshtml.IHTMLInputElementelePrice= (mshtml.IHTMLInputElement)webBrowser.Document.GetElementById("price").DomElement;
stringsValue= elePrice.value;
EDIT: This has been tested with the following code:
webBrowser.Url = newUri("http://files.jga.so/stackoverflow/input.html");
webBrowser.DocumentCompleted += (sender, eventArgs) =>
{
var eleNormal = (IHTMLInputElement)webBrowser.Document.GetElementById("normal").DomElement;
var eleReadOnly = (IHTMLInputElement)webBrowser.Document.GetElementById("readonly").DomElement;
var eleDisabled = (IHTMLInputElement)webBrowser.Document.GetElementById("disabled").DomElement;
MessageBox.Show(eleNormal.value);
MessageBox.Show(eleReadOnly.value);
MessageBox.Show(eleDisabled.value);
};
Solution 2:
try to use innertext
string price = webBrowser1.Document.GetElementById("price").InnerText;
Post a Comment for "How To Get Html Textbox Value?"