<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Xming &#8211; Henry Poon&#039;s Blog</title>
	<atom:link href="https://blog.henrypoon.com/blog/tag/xming/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.henrypoon.com</link>
	<description></description>
	<lastBuildDate>Sun, 02 Oct 2022 05:08:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">83044199</site>	<item>
		<title>Running Selenium Webdriver on Bash for Windows</title>
		<link>https://blog.henrypoon.com/blog/2017/06/18/running-selenium-webdriver-on-bash-for-windows/</link>
					<comments>https://blog.henrypoon.com/blog/2017/06/18/running-selenium-webdriver-on-bash-for-windows/#comments</comments>
		
		<dc:creator><![CDATA[hp]]></dc:creator>
		<pubDate>Sun, 18 Jun 2017 20:02:23 +0000</pubDate>
				<category><![CDATA[computer stuff]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[APT]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Drive]]></category>
		<category><![CDATA[EAR]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Free software]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Graphical user interface testing]]></category>
		<category><![CDATA[IME]]></category>
		<category><![CDATA[ise]]></category>
		<category><![CDATA[It]]></category>
		<category><![CDATA[lamb]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Net]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Run]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Sleep]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[USR]]></category>
		<category><![CDATA[Variable]]></category>
		<category><![CDATA[Vol]]></category>
		<category><![CDATA[Web browsers]]></category>
		<category><![CDATA[Web development software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Xming]]></category>
		<guid isPermaLink="false">https://blog.henrypoon.com/?p=2711</guid>

					<description><![CDATA[NOTE: This article is for WSL1, for WSL2, see this post 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&#8217;t work just work right out of the box, and the set up for it is quite convoluted. You will [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">NOTE: This article is for WSL1, for WSL2, see <a href="https://blog.henrypoon.com/blog/2020/09/27/running-selenium-webdriver-on-wsl2/" target="_blank" rel="noreferrer noopener">this post</a></p>



<p class="wp-block-paragraph">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&#8217;t work just work right out of the box, and the set up for it is quite convoluted.</p>



<p class="wp-block-paragraph">You will need</p>



<ul class="wp-block-list"><li><a rel="noreferrer noopener" href="https://msdn.microsoft.com/en-us/commandline/wsl/install_guide" target="_blank">Bash for Windows</a></li><li><a rel="noreferrer noopener" href="https://sourceforge.net/projects/xming/" target="_blank">Xming</a> &#8211; This will actually allow the Window to appear on the screen</li><li><a rel="noreferrer noopener" href="https://github.com/mozilla/geckodriver/releases" target="_blank">geckodriver</a> &#8211; Selenium now needs this to run Firefox</li></ul>



<h2 class="wp-block-heading">Bash setup</h2>



<p class="wp-block-paragraph">Install Firefox:</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">sudo apt-get install firefox</code></pre>



<p class="wp-block-paragraph">Export DISPLAY variable in ~/.bashrc. Just add this to the ~/.bashrc:</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">export DISPLAY=:0</code></pre>



<h2 class="wp-block-heading">Xming setup</h2>



<p class="wp-block-paragraph">Just download it from the link above and run it.</p>



<h2 class="wp-block-heading">Download geckodriver</h2>



<p class="wp-block-paragraph">Download geckodriver from the link above and put in the /usr/bin/ folder in Bash for Windows.</p>



<h2 class="wp-block-heading">Running Selenium</h2>



<p class="wp-block-paragraph">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 seconds and then quit.&nbsp; Make sure to have Xming running otherwise the browser isn&#8217;t going to start.</p>



<pre class="wp-block-code"><code lang="python" class="language-python">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()</code></pre>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.henrypoon.com/blog/2017/06/18/running-selenium-webdriver-on-bash-for-windows/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2711</post-id>	</item>
	</channel>
</rss>
