title: How to click on onclick link with image? Python Selenium
body: <p>I'm just learning how to webscrape dynamically using Selenium in Python. I'm currently trying to click on a link within the webpage to page forward over search results.</p>
  
  <p>So far this is the code that I'm using:</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  driver = webdriver.Chrome('C:\\Users\\km13\\chromedriver.exe')
  driver.get("http://www.congreso.gob.pe/pley-2016-2021")
  elem = driver.find_element_by_css_selector("img[src='/Sicr/TraDocEstProc/CLProLey2016.nsf/8eac1ef603908b5105256cdf006c41b1/$Body/0.AB2?OpenElement&amp;amp;FieldElemFormat=gif']")
  elem.click()
  </code></pre>
  
  <p>This is the HTML that corresponds with the element I'd like to click on:</p>
  
  <pre><code> `&lt;a href="" onclick="return _doClick('05257FB7005EB655.8eac1ef603908b5105256cdf006c41b1/$Body/0.A50', this, null)"&gt;&lt;img src="/Sicr/TraDocEstProc/CLProLey2016.nsf/8eac1ef603908b5105256cdf006c41b1/$Body/0.AB2?OpenElement&amp;amp;FieldElemFormat=gif" width="81" height="16" border="0"&gt;&lt;/a&gt;`
  </code></pre>
  
  <p>From my somewhat limited knowledge of HTML this seems like the link is actually embedded in the gif which is why I tried to use the CSS selector that goes along with that image. But this did not work.</p>
  
  <p>Any guidance would be greatly appreciated!</p>
  
  <p>Update:
  I changed my code by adding the following import</p>
  
  <pre><code>from selenium.webdriver.common.by import By
  </code></pre>
  
  <p>And I changed the following:</p>
  
  <pre><code>elem = driver.find_element(By.CSS_SELECTOR, "img[src='/Sicr/TraDocEstProc/CLProLey2016.nsf/8eac1ef603908b5105256cdf006c41b1/$Body/0.AB2?OpenElement&amp;amp;FieldElemFormat=gif']")
  elem.click()
  </code></pre>
  
  <p>Now I get an error for "no such element."</p>