如何获取
我的 ie 网页中有以下代码。我想要标签的文本值(意思是“ABCD:”)。我正在使用 ruby watir 来实现这一点。
<fieldset>
<legend class="fieldset">ABCD:</legend>
<fieldset>
我已经尝试使用下面的代码,但我不知道为什么它不起作用并给出错误(nil:NilClass 的未定义方法“文本”)
ie.element_by_xpath("//legend[contains(@class, 'fieldset')]/").text
是否还有其他方法或者我的代码中有什么问题。
I have following code in my ie web page. I want text value of tag (means "ABCD:"). I am using ruby watir for that.
<fieldset>
<legend class="fieldset">ABCD:</legend>
<fieldset>
I have tried with below code, but I don't why its not working and giving error(undefined method `text' for nil:NilClass)
ie.element_by_xpath("//legend[contains(@class, 'fieldset')]/").text
Is there any other way or is there anything wrong in my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是页面上唯一使用“fieldset”类吗?
支持的元素列表显示 Watir 未知且支持Watir-Webdriver 的图例标签。
您是否尝试过使用 Watir-Webdriver 并按照这些思路编写代码?
这更干净、更容易阅读,而且可能会更快。仅在其他方法不起作用的情况下才诉诸使用 xpath
Is that the only time the class of 'fieldset' is used on the page?
The list of supported elements shows unknown for Watir and supported for Watir-Webdriver for the legend tag.
Have you tried using Watir-Webdriver and code along these lines?
That's cleaner, easier to read, and will likely be faster. Only resort to using xpath if nothing else works