Introduction: Running Selenium Using Intel Edison (Python)
Setting up Selenium
web-driver my be intimidating, especially when you are moving towards IoT. It is even more challenging working on an IoT without any display, running headless.
Step 1: Setting Up Your Intel Edison
The first step if you have not done so, start the installation guide on your Intel Edison.
https://software.intel.com/en-us/get-started-edison-windows-step1 Be sure to walk through all five steps (the number of steps during the time of this writing). You need a Edison board with you to complete all five. The next step I HIGHLY recommend is to perform this patch that will EXPAND your partition on your system. Since you bought a 4GIG device, you should be able to use it. The Intel Edison software current does not have this fix in place yet. Hopefully this article will inspire them to do so. http://alextgalileo.altervista.org/blog/install-kernel-from-repo-onto-edison-official-image/ WARNING: If you decide to skip this step, do NOT perform opkg update more than once on your Edison. Else, you will run out of space on your Edison and have to reflash your Edison.
Step 2: Connecting and Updating Your Edison
If you haven't done
so, plug in the power to the barrel connector. I HIGHLY recommend powering from a transformer brick from a standard 120v AV to 9-12v DC converter. The Edison will adapt the voltage to 9V.
Using the standard non-Apple, mirco-USB cable, attach it to the micro-USB port closest towards the edge of the Edison (the one away from the switch).
Find what COMM port it is using and open a serial terminal. This step will vary based on your OS and the port number your computer assigns it to.
Once you get in, you need to first install the pip command which allows you to get the Python libraries. Note: Python comes pre-installed. Issue the following commands in your serial terminal or shell.
echo "src intel-iotdk http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/intel-iotdk.conf
opkg update
opkg upgrade
Create a file called base-feeds.conf in /etc/opkg. (The instructions for that are below. If you are not familiar with VI, I highly recommend learning it)
vi /etc/opkg/base-feeds.conf
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32
opkg update
opkg install python-pip
pip install --upgrade pip
Step 3: Installing Selenium and PhantomJS
This is the where
you you get selenium
pip install selenium
In order to use selenium headless, you need a headless browser. The easiest one to use so far is PhantomJS. To get this, the command is:
npm install phantomjs-prebuilt
(Do not use npm install phantomjs)
Step 4: Learning From Example
The template of your
code should resemble this one
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.PhantomJS()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()