cannot run webdriver.Firefox from selenium webdriver - python

I am having trouble using Selenium
I am using Python 3.6, on a Windows 7 machine at my workplace. Firefox is 61.0.1 (64-bit)
Python is loaded in C:\Program Files (x86)\Python36-32
My work is in H:\PythonPrograms
I have successfully installed selenium:
C:\Windows\System32>pip install selenium
Requirement already satisfied: selenium in c:\program files (x86)\python36-32\lib\site-packages (3.13.0)
Per other advice found here, I downloaded geckodriver.exe and placed it both into C:\Program Files (x86)\Python36-32 and H:\PythonPrograms.
My path includes: C:\Program Files (x86)\Python36-32\Scripts\;C:\Program Files (x86)\Python36-32\;H:\PythonPrograms
I am following the steps on "Automate the Boring Stuff with Python" (Al Sweigart) p. 257
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
browser = webdriver.Firefox()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 159, in __init__
log_path=log_path)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\service.py", line 44, in __init__
log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'
>>> browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 159, in __init__
log_path=log_path)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\service.py", line 44, in __init__
log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'
>>>
(IT's not the permissaion on geckodriver.log. This even happens when I delete that file and try again. Also I checked permissions: )
When I run Python as administrator from a new Python session:
>>> from selenium import webdriver
>>> browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
self.service.start()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'PythonPrograms' executable needs to be in PATH.
I don't understand what is happening between me running Python normally vs running as administrator. Whichever, neither way gives me expected output.
added new run example by changing the executable_path to include the program name and remove the "r" qualifier. Here are the new results:
>>> from selenium import webdriver
>>> browser = webdriver.Firefox(executable_path='H:\PythonPrograms\geckodriver.exe')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
browser = webdriver.Firefox(executable_path='H:\PythonPrograms\geckodriver.exe')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
keep_alive=True)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
>>>

Instead of using regular expression try to give exact path with exe file name
browser = webdriver.Firefox(executable_path='H:\PythonPrograms\yourexenamehere.exe')

Related

Why does Virtual Studio code keep failing to fine file or directory in python

I run my code in Pythons build in IDLE Shell and it will run no problem. But once it is in virtual studio it then throws this error code.
I have gone into my Python Extension settings and have checked the 'Execute In File Dir' like multiple other posts and fixes say, but it does not seem to resolve my issue.
Error:
Traceback (most recent call last):
File "c:\Users\dpr48\OneDrive\Desktop\Python\FINAL PROJECT\Versions\v1.0.0\Cipher Text -
v1.0.0\CipherText-v1.0.0.py", line 27, in <module>
mainwindow = MainMenu()
File "c:\Users\dpr48\OneDrive\Desktop\Python\FINAL PROJECT\Versions\v1.0.0\Cipher Text -
v1.0.0\CipherText-v1.0.0.py", line 17, in __init__
loadUi('MainMenu.ui', 'r', self)
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\site-
packages\PyQt5\uic\__init__.py", line 238, in loadUi
return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix)
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\site-
packages\PyQt5\uic\Loader\loader.py", line 66, in loadUi
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\site-
packages\PyQt5\uic\uiparser.py", line 1020, in parse
document = parse(filename)
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\xml\etree\ElementTree.py",
line 1229, in parse
tree.parse(source, parser)
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\xml\etree\ElementTree.py",
line 569, in parse
source = open(source, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'MainMenu.ui'

Error "Service.py"

I'm new in Python and Pycharm and have some problem understanding this message:
Traceback (most recent call last):
File "C:\Users\reyde\PycharmProjects\Liderws\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
PermissionError: [WinError 5] Acceso denegado
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/reyde/PycharmProjects/Liderws/Lider_ws.py", line 48, in <module>
browser21 = webdriver.Chrome(executable_path=rutaChromeDriver)
File "C:\Users\reyde\PycharmProjects\Liderws\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\Users\reyde\PycharmProjects\Liderws\venv\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Liderws' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
The error does say the webdriver has the wrong permissions. Is the path to ChromeDriver correct? Try to make the path something like:
browser21 = webdriver.Chrome(executable_path=C:\Webdrivers\chromedriver.exe)
Or wherever you have chromedriver saved, but make sure the path is directly to the exe.
Try redownloading the newest ChromeDriver available and place it in the folder you want. Don't forget to add it to system PATH and not just user.

Python Selenium " 'geckodriver' executable needs to be in PATH"

Even though I have already put geckodriver in there and I restarted my computer, it still prints the same thing.
>>>from selenium import webdriver
>>>browser = webdriver.Firefox()
Traceback (most recent call last):
File "D:\Python\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "D:\Python\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "D:\Python\lib\subprocess.py", line 992, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
self.service.start()
File "D:\Python\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.
And an error before that as well! Someone please help a newbie out. Image of the Path variable
You need to mention the path of the gecko driver executable. Below line will get you some idea.
driver=webdriver.Firefox(executable_path="add geckodriver.exe")
Hope this helps. Thanks.

Selenium test execute

Hi in Pycharm I have installed Selenium in virtualenv. I try execute
from selenium import webdriver
#from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
#binary = FirefoxBinary('/webdriver/firefox')
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django ' in browser.title
but I have error
(django_env)darek#Toshiba:~/PycharmProjects/Django$ python
functional_tests.py Traceback (most recent call last): File
"functional_tests.py", line 5, in
browser = webdriver.Firefox() File "/home/darek/.virtualenvs/django_env/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py",
line 140, in init
self.service.start() File "/home/darek/.virtualenvs/django_env/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
line 74, in start
stdout=self.log_file, stderr=self.log_file) File "/usr/lib/python3.5/subprocess.py", line 947, in init
restore_signals, start_new_session) File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg) NotADirectoryError: [Errno 20] Not a directory Exception ignored in: > Traceback (most recent call last): File
"/home/darek/.virtualenvs/django_env/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
line 173, in del
self.stop() File "/home/darek/.virtualenvs/django_env/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
line 145, in stop
if self.process is None: AttributeError: 'Service' object has no attribute 'process'
I download geckodriver ver. 11 and add to variable path and add in bashrc
export PYTHONPATH=${PYTHONPATH}:/usr/bin export
WORKON_HOME=$HOME/.virtualenvs export PROJECT_HOME=$HOME/MyProject
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 source
/usr/local/bin/virtualenvwrapper.sh
source django_env/bin/activate export
PATH=$PATH:/home/darek/webdriver/firefox/geckodriver export
PATH=$PATH:/home/darek/webdriver/firefox/wires
what can I do more?

Shelve Module Not Working

After I reinstalled Python to move it from an AppData folder to Program Files, it looks like the shelve module is no longer working and I receive the error below when I call upon shelve.open().
Please help!
>>> import shelve
>>> myShelf = shelve.open('data')
Traceback (most recent call last):
File "C:\Program Files\Python\lib\dbm\dumb.py", line 81, in _create
f = _io.open(self._datfile, 'r', encoding="Latin-1")
FileNotFoundError: [Errno 2] No such file or directory: 'data.dat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
myShelf = shelve.open('data')
File "C:\Program Files\Python\lib\shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "C:\Program Files\Python\lib\shelve.py", line 227, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "C:\Program Files\Python\lib\dbm\__init__.py", line 94, in open
return mod.open(file, flag, mode)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 303, in open
return _Database(file, mode, flag=flag)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 69, in __init__
self._create(flag)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 83, in _create
with _io.open(self._datfile, 'w', encoding="Latin-1") as f:
PermissionError: [Errno 13] Permission denied: 'data.dat'
>>>
The error "FileNotFoundError: [Errno 2] No such file or directory: 'data.dat'" shows you, it can not find the data.dat, please check the file location.
I had this problem using Windows 10. I solved the issue by changing the working directory to a folder under my profile.
os.chdir('C:\\Users\\Nat\\Documents\\Python\\Project 1')
I presume I didn't have permission to write a file 'Program Files'.

Categories

Resources