C# 使用WebBrowser.Document的表单内文本
首先感谢你为我这样的人提供的帮助。我的问题如下:C# 使用WebBrowser.Document的表单内文本,c#,html,forms,webbrowser-control,C#,Html,Forms,Webbrowser Control,首先感谢你为我这样的人提供的帮助。我的问题如下: <form id="conv_weight" action="/es/" onsubmit="execute_weight(true); return false;"> <div> Quiero convertir: <div style="width: 152px"> <input type="text" name="amount" value="1" class="convert_from" onc
<form id="conv_weight" action="/es/" onsubmit="execute_weight(true); return false;">
<div>
Quiero convertir:
<div style="width: 152px">
<input type="text" name="amount" value="1" class="convert_from" onchange="execute_weight(true);" onkeyup="execute_weight(true);" style="width: 100%" />
</div>
我正在尝试使用.NET的WebBrowser对象在网页中写入文本。问题在于,该文本位于HTML结构中的表单内。页面代码如下所示:
<form id="conv_weight" action="/es/" onsubmit="execute_weight(true); return false;">
<div>
Quiero convertir:
<div style="width: 152px">
<input type="text" name="amount" value="1" class="convert_from" onchange="execute_weight(true);" onkeyup="execute_weight(true);" style="width: 100%" />
</div>
Quiero convertir:
然后继续其他项目。我想更改文本“amount”的值。我该怎么做呢?如果您使用的是WebBrowser控件,请执行此操作
HtmlElementCollection allInputTags = webBrowser1.Document.GetElementsByTagName("input");
if (allInputTags!=null && allInputTags.Count > 0)
{
foreach (HtmlElement inp in allInputTags)
{
if (inp.Name == "amount")
{
inp.SetAttribute("value", "EnterYourValue");
break;
}
}
}
哪个WebBrowser对象?Windows窗体版本、WPF版本或其他版本?