title: Applescript if class else
body: <p>I have a applescript I have been using for a while and it works good:</p>
  <pre><code>set js to &quot;document.getElementsByClassName('The_Class')[0].click();&quot;
  
  tell application &quot;Google Chrome&quot; to tell ¬
      the front window to tell ¬
      the active tab to ¬
      set jsResult to execute javascript js
  </code></pre>
  <p>Now I want to add a <strong>if and else</strong> to it. Like this but I can't find a way to solve it:</p>
  <pre><code>if the class ('The_Class') exist then
  
    set js to &quot;document.getElementsByClassName('The_Class')[0].click();&quot;
  
       tell application &quot;Google Chrome&quot; to tell ¬
         the front window to tell ¬
         the active tab to ¬
         set jsResult to execute javascript js
  
  else
  
     tell application &quot;Google Chrome&quot; to activate
  
        tell application &quot;System Events&quot;
           keystroke &quot;r&quot; using {command down}
        end tell
  
  end if
  </code></pre>