简体   繁体   English

如何获得的文本值 <legend> 在ruby watir中使用xpath标记。(使用IE)

[英]How to get Text value of <legend> tag using xpath in ruby watir.(using IE)

I have following code in my ie web page. 我的ie网页中有以下代码。 I want text value of tag (means "ABCD:"). 我想要标签的文本值(表示“ ABCD:”)。 I am using ruby watir for that. 我正在为此使用ruby watir。

<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) 我已经尝试使用下面的代码,但是我不为什么它不起作用并给出错误(nil:NilClass的未定义方法“ text”)

ie.element_by_xpath("//legend[contains(@class, 'fieldset')]/").text

Is there any other way or is there anything wrong in my code. 我的代码中还有其他方法吗?

Is that the only time the class of 'fieldset' is used on the page? 那是页面上唯一使用“ fieldset”类的时间吗?

The list of supported elements shows unknown for Watir and supported for Watir-Webdriver for the legend tag. 支持的元素列表显示了Watir未知,图例标签的Watir-Webdriver支持。

Have you tried using Watir-Webdriver and code along these lines? 您是否尝试过使用Watir-Webdriver和这些代码进行编码?

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 如果没有其他办法,只能求助于使用xpath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM