Unable to launch selenium with python in Mac OS SUR - selenium

/usr/local/bin/python3.9 /Users/rabbu/PycharmProjects/pythonProject/seleniumpkg/Basic.py
Traceback (most recent call last):
File "/Users/rabbu/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1819, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '../drivers.chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/rabbu/PycharmProjects/pythonProject/seleniumpkg/Basic.py", line 4, in <module>
driver = webdriver.Chrome(executable_path="../drivers.chromedriver")
File "/Users/rabbu/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Users/rabbu/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/common/service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'drivers.chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1

You can use webdriver_manager to directly download and launch the driver without providing the path.
You can install by using webdriver_manager by using pip3 install webdriver_manager
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
driver.get("Your URL")

Related

Undetected chromedriver keeps crashing on Replit?

On Replit normal selenium works fine but undetected chromedriver (the python library) doesn't seem to work, here's my code:
import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get('https://google.com')
I keep getting this error:
Traceback (most recent call last):
File "main.py", line 4, in <module>
driver = uc.Chrome()
File "/home/runner/fff/venv/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 401, in __init__
super(Chrome, self).__init__(
File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 89, in __init__
self.service.start()
File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /home/runner/.local/share/undetected_chromedriver/9366826a81e09122_chromedriver unexpectedly exited. Status code was: 127
Does anyone know how to fix it? Please help, thanks so much!

How to run chromedriver using Selenium (Windows 10)?

I am attempting to automate a web browser using the environment below:
Windows10, Selenium (v3.141.0), Python (v3.7.4) chrome (v77.0.3865.90), and chromedriver (v77.0.3865.40). I installed pip, installed Selenium(using Python), set my paths in the environmental variables, called out the path to my chromedriver, and I still am running into issues.
-path using for chromedriver: "C:\webdrivers\chromedriver.exe"
-path to Python: "C:\Users\linds\AppData\Local\Programs\Python\Python37"
I have some code that I ran below with errors. Any ideas?
>>> from selenium import webdriver
>>> from selenium.webdriver.chrome.options import Options
>>> options = Options()
>>> options.add_argument('--headless')
>>> options.add_argument('--no-sandbox')
>>> options.add_argument('--disable-gpu')
>>> driver = webdriver.Chrome(options=options, executable_path='C:\webdrivers\chromedriver.exe')
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
driver = webdriver.Chrome(options=options, executable_path='C:\webdrivers\chromedriver.exe')
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.

This Exception comes while install tensorflow 1.3.0

i am getting this error while installing tensorflow 1.3.0. in the terminal of mac
Installing collected packages: tensorflow-tensorboard, backports.weakref, tensorflow
Found existing installation: tensorflow-tensorboard 0.4.0rc3
Uninstalling tensorflow-tensorboard-0.4.0rc3:
Successfully uninstalled tensorflow-tensorboard-0.4.0rc3
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/wheel.py", line 323, in clobber
shutil.copyfile(srcfile, destfile)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 97, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/backports/weakref.py'

when using selenium with phantomJS, I got a WinError 87.

I have selenium 3.6.0 and phantomjs-2.1.1-windows in my Windows 10,and set the PATH to the phantomJS.exe. When I use the code below:
driver = webdriver.PhantomJS(executable_path='')
I got the fault:
Traceback (most recent call last):
File "D:\Python 3.5.4\test\BeautifulSoup.py", line 10, in <module>
driver = webdriver.PhantomJS(executable_path='')
File "C:\Program Files\Python35\lib\site-
packages\selenium\webdriver\phantomjs\webdriver.py", line 52, in __init__
self.service.start()
File "C:\Program Files\Python35\lib\site-
packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Program Files\Python35\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Program Files\Python35\lib\subprocess.py", line 957, in
_execute_child
startupinfo)
OSError: [WinError 87] wrong parameters。
Sorry for disturbing. Actually when I set the phantomJS.exe to the $PATH. I actually do not need any argument in the webdriver.PhantomJS(). I found the doc below:
executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH

selenium browser error with Chrome

I'm getting the following error from selenium:
File "clint-selenium.py", line 58, in <module>
browser = Chrome()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 407, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 439, in _request
resp = self._conn.getresponse()
File "/usr/lib/python2.7/httplib.py", line 1136, in getresponse
response.begin()
File "/usr/lib/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.7/httplib.py", line 417, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''
I am calling it with code:
from contextlib import closing
from selenium.webdriver import Chrome # pip install selenium
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
browser = Chrome()
browser.get('http://www.google.com')
time.sleep(1)
print browser.title
browser.quit()
I have evidently done something to my laptop because this used to work. Any thoughts
EDIT
I've tried updating chromedriver but I'm now getting
Traceback (most recent call last):
File "clint-selenium.py", line 58, in <module>
browser = Chrome()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"13524.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2840.90)
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 4.4.0-45-generic x86_64)
This seems to indicate I'm still not using the latest version. I've followed a couple of guides about installation and I'm getting the same result. Any thoughts
Chromedriver was apparently updated on 2016-10-22, after which I also encountered this problem. Updating to the new version of Chromedriver (2.25) fixed it for me.