Selenium WebDriverChromer: - python

Im trying to do a selenium test with ubuntu 20.04 windows desktop,
when I write
python3 testSelenium.py
I get
Traceback (most recent call last):
File "testSelenium.py", line 13, in
driver = webdriver.Chrome(executable_path="/usr/lib/chromium-browser/chromedriver")
File "/home/romansito/python3EnvDec/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in init
self.service.start()
File "/home/romansito/python3EnvDec/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/romansito/python3EnvDec/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /usr/lib/chromium-browser/chromedriver unexpectedly exited. Status code was: 1
chrome version:
google-chrome --version
Google Chrome 94.0.4606.81

Related

Why an error occurs Status code was: -4 Termux

I installed ubuntu in termux and want to run a bot on selenium there
To do this, I installed Selenium via PIP and downloaded the official web driver from Githab and ran the initialization for the test but it gave me an error
from selenium import webdriver
driver = webdriver.Firefox(executable_path='/root/firefox_driver/geckodriver')
Error
root#localhost:~# python3 test.py
test.py:5: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Firefox(executable_path='/root/firefox_driver/geckodriver')
Traceback (most recent call last):
File "test.py", line 5, in <module>
driver = webdriver.Firefox(executable_path='/root/firefox_driver/geckodriver')
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/firefox/webdriver.py", line 172, in __init__
self.service.start()
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /root/firefox_driver/geckodriver unexpectedly exited. Status code was: -4

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")

Running selenium webdriver in AWS EC2 linux

I installed selenium on Amazon Linux AMI. I try to use python to activate it.
The error show up. I do not know what is supposed to mean. Can chrome webdriver run on that environment.
My code
from selenium import webdriver
driver = webdriver.Chrome("/home/ec2-user/dlfjj/bin/chromedriver")
Error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ec2-user/dlfjj/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/home/ec2-user/dlfjj/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 86, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home`
update:
There is new error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ec2-user/dlfjj/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/home/ec2-user/dlfjj/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/home/ec2-user/dlfjj/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /home/ec2-user/dlfjj/bin/chromedriver unexpectedly exited. Status code was: 127
The error states ...
'chromedriver' executable may have wrong permissions
... which means that it cannot be executed. It should work if you add the execute bit in the EC2 instance
$ chmod +x /home/ec2-user/dlfjj/bin/chromedriver

Error when trying to capture screenshot of a webpage using Python on Windows

I'm getting an error when trying to capture a screenshot of a webpage in Python 3.6. Tried following other posts where the same question was posed, but none of it helped. Please guide as in where I'm going wrong. Thanks.
Code:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.python.org/')
driver.save_screenshot('python_org.png')
driver.quit()
Error:
Traceback (most recent call last):
File "C:\Python36-32\lib\site- packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Python36-32\lib\subprocess.py", line 990, 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 "D:/screen_capture_3.py", line 3, in <module>
driver = webdriver.Firefox()
File "C:\Python36-32\lib\site- packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__
self.service.start()
File "C:\Python36-32\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.

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