'phantomjs' executable may have wrong permissions - python

This script works fine on Google Cloud Service. But i get error on Amazon Web Service EC2: (operation system: linux 64bit)
selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable may have wrong permissions.
Full Code:
/usr/local/lib/python3.7/site-packages/selenium/webdriver/phantomjs/webdriver.py:49: UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib64/python3.7/subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "/usr/lib64/python3.7/subprocess.py", line 1499, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "turkish.py", line 114, in <module>
bot = TransBot()
File "turkish.py", line 13, in __init__
self.driver = webdriver.PhantomJS(executable_path='/usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs')
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 56, in __init__
self.service.start()
File "/usr/local/lib/python3.7/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: 'phantomjs' executable may have wrong permissions.
I try move '/usr/local/bin' and '/usr/local/share' phantomjs file. Same error. What do you suggest? Sorry my english.

change the permissions so it is executable.
$ chmod a+x phantomsjs

Grant full permission to the phantomjs file :
sudo chmod a+rwx phantomjs

Related

OSError: [Errno 8] Exec format error: 'geckodriver' when trying to open firefox using selenium in python

from selenium import webdriver
browser = webdriver.Firefox(executable_path="/usr/bin/geckodriver")
browser.get('http://www.ubuntu.com/')
The entire stack trace looks like:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 160, in __init__
self.service.start()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: 'geckodriver'
my path to geckodriver is:
/usr/bin/geckodriver
And selenium is in:
selenium in /usr/local/lib/python3.6/dist-packages (3.12.0)
Thanks in advance!
You have most probably installed a version of geckodriver that is meant for a different OS/platform! get the correct version from https://github.com/mozilla/geckodriver/releases and replace the one you have.
Use this command to install the latest chrome driver which supports selenium:
sudo apt-get install chromium-chromedriver

Selenium webdriver not working in python with firefox

I have the most up to date firefox browser and selenium installed.
I tried running the following code:
from selenium import webdriver
browser = webdriver.Firefox()
...and received the following error:
Traceback (most recent call last):
File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\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 "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\download2.py", line 3, in <module>
browser = webdriver.Firefox()
File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 152, in __init__
self.service.start()
File "C:\Users\alisy\AppData\Local\Programs\Python\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: 'geckodriver' executable needs to be in PATH.
I have downloaded geckodriver and specified the location in PATH (and then restarted my laptop). Did the same for firefox. It made no difference.
What should I do?
This line of code solves the problem for me
driver=webdriver.Firefox(executable_path="c:/drivers/geckodriver.exe")

Starting firefox-selenium macos

I've been trying to start selenium with Firefox with python but if I understand the Error message correctly it can't find the file. I've tried to find an answer to this, but every "answer" I find is on another operating system and doesn't have to do with my problem.
I have Firefox installed and Selenium.
In the shell I enter:
from selenium import webdriver
browser = webdriver.Firefox()
and it returns:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 707, in init
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
browser = webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in init
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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: 'geckodriver' executable needs to be in PATH.

Selenium script working from console, not working in CRON - Geckodriver error

I have Selenium script running from SH file.
It is working perfectly fine when I run sh file from console,
but the same file ran from Cron job fails.
SH file:
#!/bin/sh
export DISPLAY=:10
cd /home/user
python3 selenium.py > /home/user/selenium.log 2>&1
Error which I am getting is well known:
Traceback (most recent call last): File
"/usr/local/lib/python3.5/dist-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) FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "so_login.py", line 12, in
setUp
self.driver = webdriver.Firefox() File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py",
line 142, in init
self.service.start() File "/usr/local/lib/python3.5/dist-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.
I have this error in console too, but I solved it by installing geckodriver and moving it to /usr/local/bin and it is working fine from console, but why it is not working from CRON ?
Consider using pyvirtualdisplay to manage your window session for you
Install it with pip
$ pip install pyvirtualdisplay
Then add something like the following to your code:
from pyvirtualdisplay import Display
def main():
# Display creates a virtual frame buffer and manages it for you
with Display(visible=False, size=(1200, 1500)):
# Run the test of your code here
# When your code is finished and exits the with block, the with
# context manager cleans up the virtual display for you
if __name__ == "__main__":
main()

Using Selenium on Raspberry Pi with Chromium

So I'm trying to run Selenium on my raspberry pi using Chromium and for some reason I can't get my python file to compile. I keep getting the following error:
Traceback (most recent call last):
File "test.py", line 4, in <module>
driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver.exe'))
File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 75, in start
os.path.basename(self.path), docs_msg)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Here is the python code I'm trying to run:
from selenium import webdriver
import os
driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver'))
driver.get("http://www.google.com")
driver.quit()
Any ideas?
Update
After removing the '.exe' at the end of chromedriver, it now produces the following error:
Traceback (most recent call last):
File "test.py", line 4, in <module>
driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver'))
File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 68, in start
self.service_args, env=env, stdout=PIPE, stderr=PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
Ubuntu has builds of chromium-chromedriver as .deb files for armhf.
On launchpad, therefore, you can find chromium-chromedriver armhf builds available for download. Just download the latest version, and since they have no dependencies, you can install by running dpkg -i chromium-chromedriver_58.0.3029.96-0ubuntu0.14.04.1174_armhf.deb. Then chromedriver will be available in /usr/lib/chromium-browser/chromedriver.
At the moment Chrome Driver dont support ARM processors architecture anymore.
https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=95322

Categories