I want to use selenium with chromedriver on Mac,but I have some troubles on it.
import os
from selenium import webdriver
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
DRIVER_BIN = os.path.join(PROJECT_ROOT, "bin/chromedriver_for_mac")
print DRIVER_BIN
browser = webdriver.Chrome(DRIVER_BIN)
browser.get('http://www.baidu.com/')
But I can't get the result I want.
Traceback (most recent call last):
File "/Users/wyx/project/python-scraping/se/test.py", line 15, in <module>
browser = webdriver.Chrome(DRIVER_BIN)
File "/Users/wyx/project/python-scraping/.env/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/Users/wyx/project/python-scraping/.env/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver_for_mac' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x107f96150>> ignored
Then I run brew cask install chromedriver
.And I only run this
without the driver path.
browser = webdriver.Chrome()
browser.get('http://www.baidu.com/')
But it can't work either.
Traceback (most recent call last):
File "/Users/wyx/project/python-scraping/se/test.py", line 16, in <module>
browser = webdriver.Chrome()
File "/Users/wyx/project/python-scraping/.env/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/Users/wyx/project/python-scraping/.env/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x105c08150>> ignored
Process finished with exit code 1
Finally I try to put it to /usr/bin
➜ Downloads sudo cp chromedriver /usr/bin
Password:
cp: /usr/bin/chromedriver: Operation not permitted
and I try to use export PATH=$PATH:/Users/wyx/project/python-scraping/se/bin/chromedriver_for_mac
in .zshrc . But
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
So how to solve it,I want to use it with the driver path not in the PATH so I can deploy my project easily.
Solution:
brew cask install chromedriver
which chromedriver
get the driver pathwebdriver.Chrome("/usr/local/bin/chromedriver")
But I don't know why so complex to use selenium.
Unable to launch the chrome browser“, you need to go to usr/local/bin folder and right-click chromeDriver file and open it. After this step, re-run your tests, chrome driver will work. Also, you can use Bonigarcia Webdriver Manager library in your project, for this you need to add its dependency in your project.
Follow the below steps to install the Selenium package on macOS using the setup.py file: Step 1: Download the latest source package of Selenium for python3 from here. Step 2: Extract the downloaded package using the following command. Step 3: Go inside the folder and Enter the following command to install the package.
You can install both packed (. crx file) and unpacked (directory) extensions via ChromeDriver.
For me worked like this without complicating things
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With