Reputation: 163
Trying to return all tags with all attribute values, however just some of them is being returned.
describe 'Html', :html do
before(:each) do
visit 'https://www2.losango.com.br/'
end
it 'Html' do
html = page.all('img').map { |img| img['alt'] }
print html
end
end
When I open the url "https://www2.losango.com.br/" I will find lots of img alt="", however when I run it I got the result:
Losango - Conte com a gente
Losango - Conte com a gente
Empréstimo Pessoal Losango
Crediário Losango
Seguros Losango
Seguros Losango
Simulador de Crédito ideal
Cartão de Crédito Losango
Losango - Conte com a gente
The following - img alt="Empréstimo com taxa a partir de 3.99% a.m" - is not being returned. Here is the HTML code:
<div class="banner__img">
<figure>
<img src="https://www2.losango.com.br/assets/imagens/pws/banner-emprestimo.jpg" alt="Empréstimo com taxa a partir de 3.99% a.m">
</figure>
</div>
Upvotes: 1
Views: 303
Reputation: 49880
By default Capybara only finds elements that are visible on the page. The element you're specifically asking about isn't being returned because it's not visible on the page. If you want to get all the matching elements (visible and non-visible) you can tell all
to ignore visibility checking by changing to
html = page.all('img', visible: false).map { |img| img['alt'] }
Upvotes: 1