I am trying to install selenium in my PC so I tried these:
pip install selenium
Then I went to this site to download geckodriver
and copied it to /usr/bin
.
To test if selenium is working. I ran these code and got an error(after 30sec).
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
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)
Any idea how to solve this? I searched some similar questions but didn't find a solution. I'd appriciate it if someone can provide some infomation.
OS:Ubuntu 16.04
Firefox:55
python:3.5
selenium:3.4
Problem solved! Thanks for your help guys.
Solution: make sure there is 127.0.0.1 localhost
in the file /etc/host
It turns out that I changed the file for fun a long time ago and forgot to change it back T_T. After I added the 127.0.0.1 localhost
, everything is fine.