如何在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"}
答案 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') }