Hi I have a raspberry pi 3 and decided to try get selenium running with python 3. I installed it using "pip3 install selenium" and there were no errors. After I made a small test script with this code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# create a new Firefox session
driver = webdriver.Firefox()
driver.implicitly_wait(30)
driver.maximize_window()
# Navigate to the application home page
driver.get("http://www.google.com")
# get the search textbox
search_field = driver.find_element_by_id("lst-ib")
search_field.clear()
# enter search keyword and submit
search_field.send_keys("Selenium WebDriver Interview questions")
search_field.submit()
# get the list of elements which are displayed after the search
# currently on result page using find_elements_by_class_name method
lists= driver.find_elements_by_class_name("_Rm")
# get the number of elements found
print ("Found " + str(len(lists)) + " searches:")
# iterate through each element and print the text that is
# name of the search
i=0
for listitem in lists:
print (listitem.get_attribute("innerHTML"))
i=i+1
if(i>10):
break
# close the browser window
driver.quit()
but it gives me an error:
Traceback (most recent call last):
File "/home/pi/SeleniumTest.py", line 5, in <module>
driver = webdriver.Firefox()
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
keep_alive=True)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 245, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused
Any help is appreciated, thank you :)
This error message...
selenium.common.exceptions.WebDriverException: Message: connection refused
...implies that the GeckoDriver was unable to initiate/spawn a new Web Client session/instance successfully.
The version information of the binaries you are using in-terms of might have given us some more insights into the error you are observing.
However you may need to pass the Key executable_path along with the Value referring to the absolute path of the GeckoDriver as an argument while initializing the WebDriver and WebBrowser as follows :
from selenium import webdriver
# create a new Firefox session
driver = webdriver.Firefox(executable_path=r'/path/to/geckodriver')
Test
as a non-root user.driver.quit()
within tearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.