title: Get page element by title attribute - Selenium and Java
body: <p>I'm trying to get the image which has the word "Collector" in its title and click on it.
  This is the html code for the image and its link:</p>
  
  <pre><code>&lt;a href="javascript:*command*" title="Level III: KPI Collector RYG of D D/Testing - SYS"&gt;
  &lt;img src="*unusable link because it's only valid for the specific page*" title="Level III: KPI Collector RYG of D D/Testing - SYS"&gt;
  </code></pre>
  
  <p></p>
  
  <p>The <code>&lt;a&gt;</code> and <code>&lt;img&gt;</code> tags are nested in a table cell and some divs. I didn't write the html code so don't yell at me if it's ugly :p<br>
  Here is the java code where I try to do it:</p>
  
  <pre><code>WebElement trafficLight = driver.findElement(By.xpath("//img[contains(@title,'Collector')]"));
  trafficLight.click();
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//img[contains(@title,'Collector')]"}
  </code></pre>
  
  <p>I'm pretty sure the xpath is ok so I don't think that's the issue.</p>