title: Using Selenium in Python to save a webpage on Firefox
body: <p>I am trying to use <code>Selenium</code> in <code>Python</code> to save webpages on <code>MacOS Firefox</code>. </p>
  
  <p>So far, I have managed to click <code>COMMAND + S</code> to pop up the <code>SAVE AS window</code>. However,</p>
  
  <p>I don't know how to: </p>
  
  <ol>
  <li>change the directory of the file,  </li>
  <li>change the name of the
  file, and  </li>
  <li>click the SAVE AS button. </li>
  </ol>
  
  <p>Could someone help?</p>
  
  <p>Below is the code I have use to click <code>COMMAND + S</code>:</p>
  
  <pre><code>ActionChains(browser).key_down(Keys.COMMAND).send_keys("s").key_up(Keys.COMMAND).perform()
  </code></pre>
  
  <p>Besides, the reason for me to use this method is that I encounter <strong>Unicode Encode Error</strong> when I :- </p>
  
  <ol>
  <li>write the page_source to a html file and </li>
  <li>store scrapped information to a csv file. </li>
  </ol>
  
  <p>Write to a html file:</p>
  
  <pre><code>file_object = open(completeName, "w")
  html = browser.page_source
  file_object.write(html)
  file_object.close() 
  </code></pre>
  
  <p>Write to a csv file:</p>
  
  <pre><code>csv_file_write.writerow(to_write)
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>UnicodeEncodeError: 'ascii' codec can't encode character u'\xf8' in
    position 1: ordinal not in range(128)</p>
  </blockquote>