title: Selenium/Python: JavaScript href refuses to execute
body: <p>So, I am running Selenium on Python 3.5 attempting to click a button with a JavaScript function as its href. I have tried the solutions that helped others but my issue won’t budge. </p>
  
  <p><strong>Version Inventory:</strong></p>
  
  <ul>
  <li>Selenium 3.0.2 </li>
  <li>Python 3.5.2 on Anaconda 4.1.1 </li>
  <li>Firefox 51.0.1</li>
  </ul>
  
  <p>The html of the button is below: </p>
  
  <pre><code>&lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;a href='JavaScript:SWESubmitForm(document.SWEForm11_0,c_45,"s_11_1_0_0","")' tabindex="1700"&gt;Choose Account&lt;/a&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;View a different account&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>Solutions I have tried all move to the correct element in the correct frame, and it appears as if the click is being performed without throwing any exceptions, but Selenium cannot get the script to run under any circumstance. This is baffling, as manually clicking the link in the open webdriver window operates flawlessly and loads the next page. I have JavaScript enabled through a webdriver.FirefoxProfile() object.</p>
  
  <p>The below (albeit messy) xpath is the best way I have found to move to the correct element and this does find the correct element every single time, however it doesn't execute the script under any conditions.</p>
  
  <pre><code>choose_account = driver.find_element_by_xpath('//*[/html/body/table[3]/tbody/tr/td[3]/\
  span[1]/form/table[2]/tbody/tr/td/table/tbody/tr/td/table[2]/tbody/tr[2]/td[2]/\
  table/tbody/tr[1]/td/a]')
  </code></pre>
  
  <p><strong>Method One [Failed]:</strong> Moving the mouse directly to the element and clicking. Method runs without throwing errors or exceptions. Page does not change. JS does not execute</p>
  
  <pre><code>action = webdriver.common.action_chains.ActionChains(driver)
  action.move_to_element_with_offset(choose_account, 0, 0)
  action.click()
  </code></pre>
  
  <p><strong>Method Two [Failed with error]:</strong> Attempts running the script exactly as written in the href value of the element. Throws an exception:</p>
  
  <pre><code>driver.execute_script('SWESubmitForm(document.SWEForm11_0,c_45,"s_11_1_0_0","").click();')
  </code></pre>
  
  <p><strong>The exception thrown:</strong></p>
  
  <pre><code>ReferenceError: SWESubmitForm is not defined
  </code></pre>
  
  <p><strong>Method Three[Failed]:</strong> Attempts using JavaScript executor on the element. Method runs without throwing errors or exceptions. Page does not change. JS does not execute</p>
  
  <pre><code>driver.execute_script("arguments[0].click();", choose_account)
  </code></pre>
  
  <p>Does anyone have any insight into what could be happening here? I'm really at a loss.</p>
  
  <p>M</p>
  
  <p><strong>UPDATE: [RESOLVED]</strong>
  Thanks to Lauda for suggesting to use a simpler/cleaner style of locating the anchor tag using a unique snippet contained in its href and the find_element_by_xpath() method. 
  The below code worked like a charm:</p>
  
  <pre><code>choose_account = driver.find_element_by_xpath("//a[contains(@href,'SWEForm11_0,c_45')]")
  choose_account.click()
  </code></pre>