Bash for Windows has been working pretty great for me until I needed to run Selenium Webdriver on it. I quickly learned that it wouldn’t work just work right out of the box, and the set up for it is quite convoluted.
You will need
- Bash for Windows
- Xming – This will actually allow the Window to appear on the screen
- geckodriver – Selenium now needs this to run Firefox
sudo apt-get install firefox
Export DISPLAY variable in ~/.bashrc. Just add this to the ~/.bashrc:
Just download it from the link above and run it.
Download geckodriver from the link above and put in the /usr/bin/ folder in Bash for Windows.
Here is a piece of sample Python code I used to setup the web browser. It will setup the browser, open Google, sit there for 10 second and then quit.
import time from selenium import webdriver from selenium.webdriver import DesiredCapabilities def execute_with_retry(method, max_attempts): e = None for i in range(0, max_attempts): try: return method() except Exception as e: print(e) time.sleep(1) if e is not None: raise e capabilities = DesiredCapabilities.FIREFOX capabilities["marionette"] = True firefox_bin = "/usr/bin/firefox" browser = execute_with_retry(lambda: webdriver.Firefox( firefox_binary=firefox_bin, capabilities=capabilities), 10) browser.get("https://www.google.com") time.sleep(10) browser.close()