나는이 경우에는 CSS 셀렉터와 함께 갈 것
:
#If you want all links anywhere within the div with class "name"
browser.links(:css => 'div.name a')
#If you want all links that are a direct child of the div with class "name"
browser.links(:css => 'div.name > a')
하거나 XPath를 선호하는 경우 :
#If you want all links anywhere within the div with class "name"
browser.links(:xpath => '//div[@class="name"]//a')
#If you want all links that are a direct child of the div with class "name"
browser.links(:xpath => '//div[@class="name"]/a')
예 (CSS)
다음과 같은 HTML이 있다고 가정 해 보겠습니다.
<div class="name">
<a href="http://www.example.com/link1">
This link is a direct child of the div
</a>
</div>
<div class="stuff">
<a href="http://www.example.com/link2">
This link does not have the matching div
</a>
</div>
<div class="name">
<span>
<a href="http://www.example.com/link3">
This link is not a direct child of the div
</a>
</span>
</div>
그런 다음 CSS 방법은 결과를 줄 것이다 :
browser.links(:css, 'div.name a').collect(&:href)
#=> ["http://www.example.com/link1", "http://www.example.com/link3"]
browser.links(:css, 'div.name > a').collect(&:href)
#=> ["http://www.example.com/link1"]
모든 솔루션은 실제로 중대하다. 모두에게 점수를 줄 수 있기를 바랍니다. 정말 고맙습니다. –