无法在WebBrowser中以编程方式将值设置为textBox控件 [英] Unable to set value to textBox control programatically in WebBrowser

查看:150
本文介绍了无法在WebBrowser中以编程方式将值设置为textBox控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Web浏览器中以编程方式将值设置为文本框,但它引发了Null异常。



这是代码,我试过了: -



webBrowser1.Document.GetElementById(field-summary)。InnerText =Something;

webBrowser1.Document.GetElementById(field-summary).setAttribute(value,Something);

我试图通过使用Quick手表和它在那里,但我无法设置一个值。

在此,我也附加了手表的捕捉。





这是错误,我得到了。



发生了类型为'System.Reflection.TargetInvocationException'的第一次机会异常在mscorlib.dll中



我的问题是我正在尝试为内联文本设置一个值,并且我没有对InnerText进行任何操作。但仍然是抛出错误。



我已经尝试了InnerText,值也是。但仍然无法使用。

我也附上了snap,使用Inspect作为参考。





PS:
1.所有这些代码集都在WebBrowser的DocumentCompleted Event中完成,但仍然无法完成。
2.我访问了其他页面中的其他元素(文本),并使用InnerText访问并设置了它的值。但无法处理这个元素。



有人可以说明它为什么这样做,所以我可以理解它。



谢谢。

解决方案

>

如何获取HTML文本框的值? / b>

因此,以下代码适用于我。

动态elePrice = webBrowser.Document.GetElementById ( 价格)一个DOMElement。
string sValue = elePrice.value;

谢谢。


I am trying to set a value programatically to a textbox in a web browser but it is throwing the Null exception.

This is the code, I have tried:-

webBrowser1.Document.GetElementById("field-summary").InnerText = "Something";

webBrowser1.Document.GetElementById("field-summary").SetAttribute("value", "Something");

I have tried to find the element by using the Quick Watch and it is there, but I am unable to set a value.

Hereby, I have attached the snap of watch too.

And this is the error, I am getting.

A first chance exception of type 'System.NullReferenceException' occurred in TimeSheet.exe A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

My question is I am trying to set a value to the innertext and I am not doing any manipulation with the InnerText. But still it is throwing error.

I have tried both InnerText, value too. But still unable.

I have also attached the snap, using the Inspect for reference.

PS: 1. All these code set are done in the DocumentCompleted Event of the WebBrowser, but still unable.. 2. I have accessed other elements (text) in some other pages and used the InnerText for accessing and setting a value for it. But unable to do with this element.

Could some one throw a light on why it is doing so, so I can able to understand it.

Thanks.

解决方案

Found a working solution for my problem from SO,.

How to get HTML textbox value?

So, the following code worked for me.

dynamic elePrice = webBrowser.Document.GetElementById("price").DomElement; string sValue = elePrice.value;

Thanks.

这篇关于无法在WebBrowser中以编程方式将值设置为textBox控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆