I ran the following code by installing selenium
and django
module.
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
For the selenium
module, I need geckodriver
for firefox browser.
So, I installed geckodriver by different ways - 1. npm, 2. brew, 3. direct install (download from here and move it to /usr/local/bin
or /usr/bin
. All the ways did not work for the above test code.
I got the following error message:
Traceback (most recent call last):
File "functional_tests.py", line 3, in <module>
browser.get('http://localhost:8000')
File "/Users/kiyeonj/opt/anaconda3/envs/tdd_practice/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/Users/kiyeonj/opt/anaconda3/envs/tdd_practice/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/kiyeonj/opt/anaconda3/envs/tdd_practice/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=connectionFailure&u=http%3A//localhost%3A8000/&c=UTF-8&d=Firefox%20can%E2%80%99t%20establish%20a%20connection%20to%20the%20server%20at%20localhost%3A8000.
Please let me know what the problem is..
I think you need a gecko driver as well.
You can download from here
and put it into a folder, preferably where you have your .py files
and then use it like this :-
from selenium import webdriver
driver = webdriver.Firefox(executable_path = "D:\geckodriver.exe")
driver.maximize_window()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
PS :
executable_path = 'full file path to your gecko driver'