如何获取的文本值在 ruby​​ watir 中使用 xpath 进行标记。(使用 IE)

发布于 2024-12-13 21:37:51 字数 371 浏览 5 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光瘦了 2024-12-20 21:37:51

这是页面上唯一使用“fieldset”类吗?

支持的元素列表显示 Watir 未知且支持Watir-Webdriver 的图例标签。

您是否尝试过使用 Watir-Webdriver 并按照这些思路编写代码?

puts browser.legend(:class => 'fieldset').text

这更干净、更容易阅读,而且可能会更快。仅在其他方法不起作用的情况下才诉诸使用 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?

puts browser.legend(:class => 'fieldset').text

That's cleaner, easier to read, and will likely be faster. Only resort to using xpath if nothing else works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文