Selenium with Python
Debugging
Use something like http://www.pyzo.org/pyzo_intro.html
Documentation
http://selenium-python.readthedocs.io/api.html?highlight=phantom#module-selenium.webdriver.remote.webdriver
Find Selenium Version
$> python
>>> import selenium >>> help (selenium) (...) DATA __version__ = '3.8.0' VERSION 3.8.0
Also you can check a pip package version with:
$ pip show selenium
Installation
- Note down your Firefox version (in my case 52.5.1 ESR)
Maybe install an Extended Support Release (ESR) type and disable updates to make sure you get a constant development environment. Note that you will be more exposed to security flaws by not updating. - Get Python. In my case I used Python 2.7.8.
Install it with python version manager:
https://github.com/pyenv/pyenv
Follow instructions from the link above, namely :$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv $ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile $ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile $ reboot # after reboot $ pyenv install 2.7.8
- Get Selenium for Python. In my case I used Selenium 3.8.0
pip install selenium==3.8.0
- Get PhantomJS binary and put it on path
https://bitbucket.org/ariya/phantomjs/downloads/ - Get Firefox geckowebdriver and put it on path.
https://github.com/mozilla/geckodriver/releases
Make sure you use a web driver version compatible with your selenium version.
To find selenium version see previous section.
Troubleshooting
Problem: WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
or
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Solution
https://github.com/mozilla/geckodriver/releases
Put geckodriver.exe in your PATH or in the current directory.
Problem : Firefox displays : Your connection is not secure
Solution : Help needed! I still don't know how to resolve. Even with a loaded profile. This happens on Windows, but not on Linux.
Problem: selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH.
Recent Comments