如何通过ID获取HtmlElement [英] How to get a HtmlElement by Id

查看:175
本文介绍了如何通过ID获取HtmlElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要通过ID(编码的UI)找到HtmlElement。我有一个BrowserWindow。可以找到特定的元素(表格,单元格,按钮等),但不仅可以通过其ID查找任意元素。例如,以下h3(在现实生活中,h3是复杂表单元格的一部分。我们不需要该单元格,只需要标题)。

Need to find a HtmlElement by Id (coded-ui). I got a BrowserWindow. Can find a specific element (table, cell, button, etc.), but not just an arbitrary element by its Id. E.g., the following h3 (in real life the h3 is part of complex table cell. We don't need the cell, we just need the header).

<html>
<body>
   <h3 id='check'>Check this text!</h3>
</body>
</html>

有人知道怎么做吗?感谢您的放心!
Gerard

Anybody an idea how to do this? Thanks in advace! Gerard

推荐答案

Onilol建议执行以下操作(由于id是固定的,所以很好用,我们只需要文本即可) :

Onilol suggested the following (which works fine as the id is fixed and we just need the text):

var browser = BrowserWindow.Launch("http://www.oursite.check/");
object txt = browser.ExecuteScript("return $('#check').text()", null);

这篇关于如何通过ID获取HtmlElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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