I'm having an issue getting the list of links of the pages and saving it as an array, so I can find out what links are used in the page
<ul class="test">
<li class="social_1"></li>
<a href="link1"></a>
<li class="social_2"></li>
<a href="link2"></a>
<li class="social_3"></li>
<a href="link3"></a>
<li class="social_4"></li>
<a href="link4"></a>
</ul>
I tried using
list_items = page.all('li').collect(&:href)
puts list_items;
but it's not giving the correct answer.
im having this error
undefined method `href' for #<Capybara::Element tag="li"> (NoMethodError)
There are two issues:
[]
method.Depending on your preference, any of the following would work:
page.all('li').map { |li| li.find('a')['href'] }
page.all('li a').map { |a| a['href'] }
page.all('a').map { |a| a['href'] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With