title: Find the name of a link image with Selenium in Python
body: <p>I have an html file with links and would like to distinguish if a link is an image or if a link is text. I am using Python 3 and Selenium with Firefox or PhantomJS browser. The goal is to have an automatic procedure to go through several hundred html files and find links with images.</p>
  
  <p>What I do:
  I first focus only on one html file.
  In a first step I get the names of all images in the html file, where I know that one image is a link and the others are not. I call the images IMAGENAME.</p>
  
  <p>Then I try to derive if one or more of the images is a link. I use:</p>
  
  <pre><code>driver.find_element_by_xpath('(//a[/img[contains(text(),"'+IMAGENAME[j]+'")]])')
  or 
  driver.find_element_by_xpath('//a[/img[contains(@src,IMAGENAME[j])]]') 
  or 
  driver.find_element_by_xpath('//a/img[contains(@src,IMAGENAME[j])]') 
  with j = 0 (image is not a link) and j = 1 (image is a link).
  </code></pre>
  
  <p>In each case I get the same error message, which tells me that the way I call the image must be wrong:</p>
  
  <pre><code>NoSuchElementException: Message: no such element: Unable to locate element:...
  </code></pre>
  
  <p>When I leave the <code>//a</code> part out and use only <code>//img</code>, then I get all images without error message.</p>
  
  <p>What am I doing wrong in calling the image in a link? Is there another way I can do this?</p>