title: Calling Javascript function in Applescript
body: <p>I am trying to automate a javascript function call on an external webpage. </p>
  
  <p>the line of code I want to execute is triggered by the click of this div</p>
  
  <pre><code>&lt;div class="vote_btn 151" onclick="vote('151', 'California Square Red Paso','145');"&gt;&amp;nbsp;VOTE ►&lt;/div&gt;
  </code></pre>
  
  <p>Instead of automating the clicking of the div, I am just skipping to calling the vote function. I am attempting to do this in two browsers. Here is the applescript for safari:</p>
  
  <pre><code>tell application "Safari" to do JavaScript "vote('151', 'California Square Red Paso', '145');" in document 1
  </code></pre>
  
  <p>and for chrome:</p>
  
  <pre><code>tell application "Google Chrome"
  
      tell window 1
  
          tell tab 1
  
              execute javascript "vote('151', 'California Square Red Paso', '145');"
  
          end tell
  
      end tell
  
  end tell
  </code></pre>
  
  <p>the problem is, I am getting weird errors. For chrome, it says "vote is not defined" and safari "variable vote is not defined". It seems like my applescripts aren't able to access the javascript? I know there are similar questions to this on stackoverflow but I have read and tried all of the solutions from them with no successful results. Any help will be greatly appreciated!</p>