通过获得价值html元素 [英] Get html element by value
问题描述
,我试图让与值=type102
$的第二个元素b $ b
< DIV CLASS =输入><输入类型=电台NAME =输入值=type101
的onclick =的setType('type101');>&下; A HREF =JavaScript的:的setType('type101');
的onclick =s_objectID =安培; QUOT;的javascript:的setType('type101'); _ 1安培; QUOT ;;返回this.s_oc
this.s_oc(五):真正的> type101< / A>< / DIV>
< DIV CLASS =输入><输入类型=电台NAME =输入值=type102
的onclick =的setType('type102'); 检查=选中>< A HREF =JavaScript的:的setType('type102');
的onclick =s_objectID =安培; QUOT;的javascript:的setType('type102'); _ 1安培; QUOT ;;返回this.s_oc
this.s_oc(五):真正的> type102< / A>< / DIV>
我使用
的HtmlElement htmlElem = browser.Document。的getElementById(....
和
的HtmlElement htmlElem = browser.Document.All.GetElementsByName(....
之前,但在这种情况下它们都相同的,所以将需要通过数值或HREF
获得是否有可能直接拿到的第二个元素,无需外部库或我将不得不通过他们获得GetElementsByName的收集和循环<? / p>
HtmlElementCollection COL = webBrowser1.Document.GetElementsByTagName(输入);
的HtmlElement希望;
的foreach(在的HtmlElement山坳项)
{
如果(item.GetAttribute(值)==type102)
$ { b $ b =就想项目;
中断;
}
}
Given the following html in a Winforms Webbrowser DOM, I'm attempting to get the second element with value="type102"
<div class="Input"><input type="radio" name="type" value="type101"
onclick="setType('type101');"><a href="javaScript:setType('type101');"
onclick="s_objectID="javascript:setType('type101');_1";return this.s_oc?
this.s_oc(e):true">type101</a></div>
<div class="Input"><input type="radio" name="type" value="type102"
onclick="setType('type102');" checked="checked"><a href="javaScript:setType('type102');"
onclick="s_objectID="javascript:setType('type102');_1";return this.s_oc?
this.s_oc(e):true">type102</a></div>
I've used
HtmlElement htmlElem = browser.Document.GetElementById(....
and
HtmlElement htmlElem = browser.Document.All.GetElementsByName(....
before, but in this instance they are both the same so would need to get by value or href
Is it possible to get the second element directly without external libraries or would I have to get a collection of GetElementsByName and iterate through them?
HtmlElementCollection col= webBrowser1.Document.GetElementsByTagName("input");
HtmlElement wanted;
foreach (HtmlElement item in col)
{
if (item.GetAttribute("value")=="type102")
{
wanted = item;
break;
}
}
这篇关于通过获得价值html元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!