R
ralpugan
Hello,
It may sound as a weird problem, when you use InnerText to "get" the
value of an element it returns nothing, but works fine when you set
text using InnerText.
Steps to reproduce: 1) Create a winform application having a
webbrowser placed on it and a button.
2) Navigate to "www.google.com" using
webbrowser1.Navigate or assigning its "url" property (up to you).
3) Highlight search textbox of Google.
(click on it)
4) In button's click event handler (or
whenever you want to get), try:
WebBrowser1.Document.ActiveElement.InnerText = "hello"
.....and it works. But if you want to GET typed text on search textbox,
it returns null or nothing:
MsgBox
(WebBrowser1.Document.ActiveElement.InnerText.ToString)
...doesn't work! (null reference exception).
Also that doesn't work though you search entire element collection by
specifiying name of element explictly:
MsgBox(WebBrowser1.Document.All.GetElementsByName("q").Item
(0).InnerText.ToString)
...which doesn't work also!
The only workaround i found is explictly specifiying its attribute
("value") as follows:
MsgBox(WebBrowser1.Document.All.GetElementsByName("q").Item
(0).GetAttribute("value").ToString)
....which works fine
So, why cannot InnerText property doesn't return value of a text
element on webbrowser, whereas it can set value fine?
Regards,
ralpugan
It may sound as a weird problem, when you use InnerText to "get" the
value of an element it returns nothing, but works fine when you set
text using InnerText.
Steps to reproduce: 1) Create a winform application having a
webbrowser placed on it and a button.
2) Navigate to "www.google.com" using
webbrowser1.Navigate or assigning its "url" property (up to you).
3) Highlight search textbox of Google.
(click on it)
4) In button's click event handler (or
whenever you want to get), try:
WebBrowser1.Document.ActiveElement.InnerText = "hello"
.....and it works. But if you want to GET typed text on search textbox,
it returns null or nothing:
MsgBox
(WebBrowser1.Document.ActiveElement.InnerText.ToString)
...doesn't work! (null reference exception).
Also that doesn't work though you search entire element collection by
specifiying name of element explictly:
MsgBox(WebBrowser1.Document.All.GetElementsByName("q").Item
(0).InnerText.ToString)
...which doesn't work also!
The only workaround i found is explictly specifiying its attribute
("value") as follows:
MsgBox(WebBrowser1.Document.All.GetElementsByName("q").Item
(0).GetAttribute("value").ToString)
....which works fine
So, why cannot InnerText property doesn't return value of a text
element on webbrowser, whereas it can set value fine?
Regards,
ralpugan