【问题标题】:How to get Span collection by id in Watir如何在 Watir 中通过 id 获取 Span 集合
【发布时间】:2021-05-04 11:19:42
【问题描述】:

watir 中是否有一种方法可以通过 id 获取所有 span 集合的列表。我只能通过索引和一次一项来遍历跨度标签。 我想获取跨度标签的整个集合并循环遍历它。

    irb(main):060:0> ie.span(:id =>/ctl00_ContentPlaceHolder1_DataList1_ctl132_lblSubject/).text
=> "30 stuff"

irb(main):065:0> ie.span(:id =>/ctl00_ContentPlaceHolder1_DataList1_ctl/).exists?
=> true
irb(main):073:0> spans=ie.span(:id =>/ctl00_ContentPlaceHolder1_DataList1_ctl/ ,:index=>3)
=> #<Watir::Span: located: false; {:id=>/ctl00_ContentPlaceHolder1_DataList1_ctl/, :index=>3, :tag_name=>"span"}>
irb(main):074:0> spans.text
=> "Well, morning."
irb(main):075:0>

【问题讨论】:

    标签: ruby watir


    【解决方案1】:

    是的,您可以迭代。编写如下代码

    ie.spans(:id =>/ctl00_ContentPlaceHolder1_DataList1_ctl/).each do |span|
      p span.text
    end
    

    它将打印所有与您的 id 匹配的跨度文本。

    【讨论】:

      猜你喜欢
      • 2013-07-29
      • 1970-01-01
      • 2014-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多