title: How to Dynamically Call a Username in a File Directory with Python
body: <p>So I am trying to call a username inside of a python command to instantiate the Selenium Driver.</p>
  <pre class="lang-py prettyprint-override"><code># WebDriver Path for System
  if platform.system() == ('Windows'):
      browser = webdriver.Chrome(&quot;C:\Program Files (x86)\Google\Chrome\chromedriver.exe&quot;,options=chrome_options)
  elif platform.system() == ('Linux'):
      browser = webdriver.Chrome(executable_path='/home/$USER/Drivers/Google/Chrome/chromedriver',options=chrome_options)
  elif platform.system() == ('Darwin'):
      browser = webdriver.Chrome(executable_path='/Users/$USER/Drivers/Google/Chrome/chromedriver',options=chrome_options)
  else:
      print(&quot;Are you sure you have the Selenium Webdriver installed in the correct path for your Browser?&quot;)
  </code></pre>
  <p>However, the <code>$USER</code> will not work. I have tried calling it as</p>
  <pre class="lang-py prettyprint-override"><code>username
  </code></pre>
  <p>AND:</p>
  <pre class="lang-py prettyprint-override"><code>print(username)
  </code></pre>
  <p>from within the directory as follows</p>
  <pre><code>username = getpass.getuser()
  print(username)
  
  # WebDriver Path for System
  if platform.system() == ('Windows'):
      browser = webdriver.Chrome(&quot;C:\Program Files (x86)\Google\Chrome\chromedriver.exe&quot;,options=chrome_options)
  elif platform.system() == ('Linux'):
      browser = webdriver.Chrome(executable_path='/home/username/Drivers/Google/Chrome/chromedriver',options=chrome_options)
  elif platform.system() == ('Darwin'):
      browser = webdriver.Chrome(executable_path='/Users/username/Drivers/Google/Chrome/chromedriver',options=chrome_options)
  else:
      print(&quot;Are you sure you have the Selenium Webdriver installed in the correct path for your Browser?&quot;)
  </code></pre>
  <p>However, it doesn't seem to work and it just gives me a following traceback, when I run it indicating that it's not recognized.</p>
  <pre class="lang-py prettyprint-override"><code> rbarrett@MacBook-Pro  ~/Projects/Mirantis/Train  python scrape_creds.py                       ✔  3812  14:36:47
  rbarrett
  The file secrets.gpg does not exist and the secrets file is not using GPG Encryption
  GPG Encryption is not Enforced on secrets.json
  Your Current Version of the Chrome is:
  86.0.4240.80
  Using Target URL:
  https://mirantis.awsapps.com/start/#/
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.8/site-packages/selenium/webdriver/common/service.py&quot;, line 72, in start
      self.process = subprocess.Popen(cmd, env=self.env,
    File &quot;/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py&quot;, line 854, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File &quot;/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py&quot;, line 1702, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  FileNotFoundError: [Errno 2] No such file or directory: '/Users/$USER/Drivers/Google/Chrome/chromedriver'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;scrape_creds.py&quot;, line 202, in &lt;module&gt;
      browser = webdriver.Chrome(executable_path='/Users/$USER/Drivers/Google/Chrome/chromedriver',options=chrome_options)
    File &quot;/usr/local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py&quot;, line 73, in __init__
      self.service.start()
    File &quot;/usr/local/lib/python3.8/site-packages/selenium/webdriver/common/service.py&quot;, line 81, in start
      raise WebDriverException(
  selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
  </code></pre>
  <p>Does anyone have any thoughts on how I can dynamically piece in information into those webdriver directories that will allow me to have the <code>username</code> work inside that command string?</p>
  <p>Example:</p>
  <pre><code>/Users/username/Drivers/Google/Chrome/chromedriver'
  </code></pre>
  <p>where username gives the string as <code>echo $USER</code> or <code>print(username)</code>?</p>