selenium webdriver.firefox() Error [duplicate] - python

This question already has answers here:
Selenium using Python - Geckodriver executable needs to be in PATH
(36 answers)
Closed 5 years ago.
I am trying to use selenium to start google chrome but i get an error
here is my code:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
here is the error:
Traceback (most recent call last):
File "functional_tests.py", line 5, in <module>
browser = webdriver.Firefox(firefox_binary=binary)
File "C:\Python27\lib\site-
packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x03D51FD0>> ignored
any help with that?

Make sure you have latest geckodriver and firefox is installed in default dir.
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH leads to geckodriver issue, can be solved by providing the path to the geckodriver. Possible reason, geckdriver location is not added to the PATH.
binary = FirefoxBinary('path')
browser = webdriver.Firefox(firefox_binary=binary)
Exception AttributeError: "'Service' object has no attribute 'process'" looks like to me your firefox is installed in custom location. Please confirm.

Related

Errror with using Selenium Webdriver with chrome

from bs4 import BeautifulSoup, SoupStrainer
from selenium import webdriver
from selenium.webdriver import chrome
from selenium.webdriver.chrome.options import Options
url = 'https://...'
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument("--headless")
driver = webdriver.Chrome('path')
driver.get(url)
Error:
Traceback (most recent call last):
File "", line 20, in <module>
driver.get(EPL_url)
File "", line 333, in get
self.execute(Command.GET, {'EPL_url': url})
File "", line 321, in execute
self.error_handler.check_response(response)
File "", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/9df33bd6f0e57084300c81738cf6c2d5/EPL_url
I have tried to look at all the potential errors around this and have found nothing. The annoying things is, the "driver.get()" function was working perfectly earlier. It only seemed to have been disrupted after I had changed the variable name of the URL. I seriously do not know what to do and need to get this code back up and running.
Please help me with the above error so I can rectify this!! It would be much appreciated.
This issue can be because of the path of the chrome driver.
Here's a simpler solution: install the python-chrome drive package, import it in your script, and it's done.
Step by step:
pip install chromedriver-binary
import the package
from selenium import webdriver
import chromedriver_binary # Adds chromedriver binary to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
Reference: https://pypi.org/project/chromedriver-binary/

chrome driver install with selenium

I have properly install selenium and chromedriver and wanted to execute this below code at python
import selenium
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r"C:\Users\SM.Nibir\Desktop\Python\chromedriver_win32\chromedriver.exe")
but I am getting these errors on my output panel
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/SM. Nibir/Desktop/Python/import os.py", line 3, in <module>
driver = webdriver.Chrome()
File "C:\python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\python\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Who can I solve this problem and make this code work properly?
first of all, your first mistake is that you wrote "import selenium from.."
so the order has to be that way:
from selenium import webdriver
driver=webdriver.Chrome(executable_path=r"C:\Users\...chromedriver.exe")
ofcourse that you need to change the path for the correct location of your chromedriver.exe file.
let me know if it helps.

How to run selenium webdriver with Python in CentOS 6.10 with Firefox

I'm trying to run a Python script in a CentOS server. However, I've been unable to install Google Chrome (I've read it is no longer supported by CentOS) so I decided to try with Firefox. However, I get the following error when trying to run it with Firefox.
Traceback (most recent call last):
File "/home/uscomplianceserv/public_html/scrapdata/FMCSAScraper.py", line 73, in <module>
init_selenium()
File "/home/uscomplianceserv/public_html/scrapdata/FMCSAScraper.py", line 40, in init_selenium
webdriver.Firefox(firefox_options = options, executable_path='/home/uscomplianceserv/public_html/scrapdata/geckodriver')
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 133, in __init__
if options.binary is not None:
AttributeError: 'Options' object has no attribute 'binary'
This is what I'm using:
Centos 6.10
Python 2.7
Selenium 3.14.0
Firefox 45
Geckodriver v0.21.0
This is the selenium webdriver initialization function:
def init_selenium():
global driver, page
options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(firefox_options = options, executable_path='/home/uscomplianceserv/public_html/scrapdata/geckodriver')
driver.get(url)

Running Selenium on AWS Ubuntu - Error: Could not find firefox in your system PATH

I am running python 2.7.12 with selenium version 2.53.6 and firefox 46.0.1 on an AWS Ubuntu Server 16.04 LTS instance. I've installed pyvirtualdisplay.
When I run this code:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Firefox()
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/anaconda2/lib/python2.7/site- packages/selenium/webdriver/firefox/webdriver.py", line 55, in __init__
self.binary = firefox_binary or capabilities.get("binary", FirefoxBinary())
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 47, in __init__
self._start_cmd = self._get_firefox_start_cmd()
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 163, in _get_firefox_start_cmd
" Please specify the firefox binary location or install firefox")
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox
I've tried to add a link to my bash profile
echo export 'PATH="$PATH:/home/firefox"' >> ~/.bashrc
But have not been successful. Any help would be greatly appreciated.

trying to set path for selenium / phantomjs on win7

I'm trying to work through http://blog.likewise.org/2013/04/webdriver-testing-with-python-and-ghostdriver/. My development environment is a usb drive on win7. I have phantomjs.exe on:
f:/phantomjs.exe
Using the python REPL I have done the following based on the article:
>>> from selenium import webdriver
>>> driver = webdriver.PhantomJS(executable_path="F:\phantomjs.exe")
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "F:\envs\r1\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 50, in __init__
self.service.start()
File "F:\envs\r1\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 66, in start
raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen
How can I fix this?
Following Can't run PhantomJS in python via Selenium, I uninstalled selenium from my virtualenv and ran:
pip install selenium==2.37
So far this has been working for me , although the above articles indicates there are some problems at least.

Categories

Resources