无法找到嵌套的p元素

时间:2015-06-02 15:06:41

标签: ruby-on-rails rspec watir watir-webdriver page-object-gem

如何在HTML中找到“tile”元素:

<div class="con-head">
  <div class="up-at js-con-dates">
    <span class="bold">Last date</span>
    7:13 PM <br>
    <span class="bold">Save</span>
    7:12 PM
  </div>
  <p class="tile">Text: Kids </p>
  <p class="desc js-desc" style="">Q&A </p>
</div>

我试图用访问者找到它:

div(:my_title) { div_element(:class => 'con-head').div_element(:class => 'tile') }

但它不起作用并给出错误:

Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"tile", :tag_name=>"div"}

1 个答案:

答案 0 :(得分:1)

在HTML中,具有“tile”类的元素实际上是p元素:

<p class="tile">Text: Kids </p>

因此,您需要使用paragraph_element方法而不是div_element方法找到它:

div(:my_title) { div_element(:class => 'con-head').paragraph_element(:class => 'tile') }