title: Watir or Selenium webdriver - Find for IMG SRC duplicated
body: <p>Is there any possible way to index/list and compare <code>&lt;img src=""&gt;</code> values using watir or selenium webdriver?.</p>
  
  <p>Update #1</p>
  
  <p>I've succesfully managed to progress on the general script for finding the right <code>&lt;div&gt;</code> that contains the pictures</p>
  
  <pre><code>require 'watir-webdriver'
  require 'selenium-webdriver'
  b = Watir::Browser.new :firefox
  
  $i = 1
  
  (1..1000).each do |i|
    b.goto 'http:example.com'
    b.div(:id, 'pic_container').wait_until_present
    puts 'div present'
  
  begin
    if
  
    else
  
    end
  
  end
  b.close
  </code></pre>
  
  <p>There will be more coding, only thing i can't resolve is enumerate all pictures available, comparing their sources and output the results.</p>
  
  <hr>
  
  <p>Update #2</p>
  
  <p>Thanks both JustinKo and Carldmitch for their answers. I went to this now:</p>
  
  <pre><code>require 'watir-webdriver'
  require 'selenium-webdriver'
  
  b = Watir::Browser.new :firefox
  b.goto 'https://trafficmonsoon.com'
  
  begin
    Watir::Wait.until { b.url == "http://example.com" }
    b.a(:href, "http://example.com/img").wait_until_present
    b.a(:href, "http://example.com/img").click
    Watir::Wait.until { b.url == "http://example.com/img" }
    b.driver.manage.timeouts.implicit_wait = 10
    b.a(:class, "btn").click
  end
  
  $i = 1
  
  (1..1000).each do |i|
    b.driver.manage.timeouts.implicit_wait = 30
    pics_set = b.div(:id, 'pics_container').images
    pics_array = []
    pics_set.each_with_index do |image|
      pics_array.push(image.current_src)
    end
    puts pics_array.find_all {|e| pics_array.rindex(e) != pics_array.index(e) }.uniq
  
  end
  b.close
  </code></pre>
  
  <p>The only problem here, is that, it is no showing which picture is duplicated, instead of, it only shows all <code>img src</code> without the one duplicated. Any hint on this?.</p>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <p>Update #3</p>
  
  <p>I got it working, it prints out the duplicated <code>img src</code>, but can't use the output data to do some web browser interactions, (clicks &amp; drags)</p>
  
  <hr>
  
  <p>Update #4</p>
  
  <p>I've succesfully managed to interact with the data, only thing i want to know, is there any way to pic one or another duplicated picture?, since both ahve the same <code>img src</code>it's impissible to click or drag from that attibute.</p>
  
  <p>Here is the code that i've got by now</p>
  
  <pre><code>require 'sub'
  require 'watir-webdriver'
  require 'selenium-webdriver'
  
  b = Watir::Browser.new :firefox
  
  b.goto 'https://example'
  
  begin
    Watir::Wait.until { b.url == "http://example.com/img" }
    b.a(:href, "http://example.com/imgs").wait_until_present
    b.a(:href, "http://example.com/imgs").click
    Watir::Wait.until { b.url == "http://example.com/imgs" }
    b.driver.manage.timeouts.implicit_wait = 10
    b.a(:class, "btn btn-xs btn-danger").click
  end
  
  b.driver.manage.timeouts.implicit_wait = 30
  pics_set = b.div(:id, 'site_loader').images
  pics_array = []
  pics_set.each_with_index do |image|
    pics_array.push(image.current_src)
  end
  duplicated = pics_array.find_all {|e| pics_array.rindex(e) != pics_array.index(e) }.uniq
  duplicated[0].sub!("http://example.com
  b.img(:src, duplicated).click", ".")
  </code></pre>
  
  <hr>
  
  <p>Update #5</p>
  
  <p>Here is an example of the <code>div</code>i'm diggin' into</p>
  
  <pre><code>&lt;div id="pic_container"&gt;
    &lt;img src="./images/test/3.png" style="cursor:pointer;width:64px" onclick="checkClick ("7hva9f")"&gt;
    &lt;img src="./images/test/5.png" style="cursor:pointer;width:59px" onclick="checkClick ("xt0nnc")"&gt;
    &lt;img src="./images/test/5.png" style="cursor:pointer;width:67px" onclick="checkClick ("1tyz9b")"&gt;
    &lt;img src="./images/test/1.png" style="cursor:pointer;width:67px" onclick="checkClick ("300yp7")"&gt;
    &lt;img src="./images/test/7.png" style="cursor:pointer;width:67px" onclick="checkClick ("pzxgyh")"&gt;
  &lt;/div&gt;
  </code></pre>