Вопрос

I want to count the images displayed in a page using capybara.The html code displayed below.for that i use following code to return the total count but the count returns 0.In my page i have 100 more images.

  c= page.all('.thumbnail_select').count

    puts c(returns 0)

HTML

<a class="thumbnail thumbnail_img_wrap">
    <img alt="" src="test.jpg">
    <div class="thumbnail_select">
  <div class="thumail_selet_backnd"></div>
  <div class="thumbil_selt_text">Click to Select</div>
</div>
          <p>ucks</p>
          <span class="info_icon"><span class="info_icon_img"></span></span>
        </a>


<a class="thumbnail thumbnail_img_wrap">
  <img alt="" src="test1.jpg">
   <div class="thumbnail_select">
  <div class="thumail_selet_backnd"></div>
  <div class="thumbil_selt_text">Click to Select</div>
</div>
    <p>ucks</p>
  <span class="info_icon"><span class="info_icon1_img"></span></span>
</a>

.........

.........

How can i count the total images?

Это было полезно?

Решение

You have a few options.

Either find all div's with class thumbnail_select by using all("div[class='thumbnail_select']").count But this is an awkward way of doing it since it looks for the div and not the images.

A better way would to be to look for all images using all("img").count as long as no other image is present on the page.

If neither of these works either the problem might be that your page is not loaded when you start looking for the images. Then just simply put a page.should have_content check before the image count to make sure that the page is loaded.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top