C# code:
GeckoElementCollection _Ellements = geckoWebBrowser1.Document
.GetElementsByTagName("input");
foreach (GeckoElement _e in _Ellements)
{
if (_e.GetAttribute("value") == "username"
{
// Code here if statement = true
}
}
HTML Code:
<input type="text" name="user" id="smf_autov_username" size="30" tabindex="1" maxlength="25" value="" class="input_text">
This code gets called every second to see if the user has changed the content of the textbox but it doesn't work, Help please :(
If I understand your question correctly, the problem is that the value of elements that are normally part of a <form>
are not available when just reading the DOM. The browser expects them to be used when the form is submitted.
The good news is, it's not hard to make the value available to your c# program, because javascript can read it, and put it somewhere that c# can get at it. You just have to have a bit of javascript that copies the @value to an attribute (like @data-value) that your c# can see. This can be done during a blur or keyup handler. For example:
<input id="foo" onblur="this.setAttribute('data-value', this.value)"></input>
This says that when the "blur" event happens (e.g. when you leave the field), copy the value over to another attribute named 'data-value' (nothing special about that name, it could just as well be named data-foobar). Then in your c#, you can read it like this:
if(_e.GetAttribute("data-value")) == "username")
For more examples, see these stackoverflow questions:
Now, I see you're checking every second, rather than triggering on some event. Maybe you'll want to do the copying to data-value on every keyup instead of blur. Note that if you need to, you can also cause the blur yourself in c#:
var activeElement = _browser.Window.Document.ActiveElement;
if(activeElement!=null)
activeElement.Blur();