C# webbrowser如何访问HtmlElement CSS类?
我正在尝试填写网络表格。我们如何访问html中的HTML元素类?通常我们使用这段代码:
webBrowser2.Document.GetElementById
html如下:
<select class="birthday_day" name="birthday_day" >
<option value="0">---</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
I am trying to fill out a web form. How do we access a class of HTML element in html? Normally we use this code:
webBrowser2.Document.GetElementById
The html is below:
<select class="birthday_day" name="birthday_day" >
<option value="0">---</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想通过名称而不是类来执行此操作,因此您可以尝试使用 Document.All 属性:
You probably want to do it by name, not class, so you could try using the Document.All property:
考虑使用 getAttribute - http://msdn.microsoft .com/en-us/library/system.windows.forms.htmlelement.getattribute.aspx CLASS 和 NAME 都应该可用。
Consider using getAttribute - http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.getattribute.aspx both CLASS and NAME should be available.
老问题,但因为很难找到:
正如前面提到的,
GetAttribute
是答案的一部分。技巧是使用正确的属性名称:这不是 WebBrowser 控件的怪癖,而是 DOM API 从那时起,在 JavaScript 中使用诸如
class
之类的关键字作为属性名称是一个巨大的问题。Old question, but since it's rather hard to find:
As previously mentioned
GetAttribute
is part of the answer. The trick is to use the correct attribute name:This is not a quirk of the WebBrowser control, but legacy of the DOM API from back when it was a huge problem to have keywords such as
class
as property names in JavaScript.