Chrome116 chromedriver 下载及配置

踩坑

Posted by Yuankun Li on 2023-09-04

chromedriver 116 版本下载

新版本下载后是Google Chrome for Testing.app, 官网介绍Chrome for Testing: reliable downloads for browser automation

chromedriver 环境变量配置

我下载的版本是: 116 mac-arm64

  • 下载后chrome-mac-arm64.zip解压为:/chrome-mac-arm64/Google Chrome for Testing.app
  • /usr/local下新建文件夹chromedriver
  • 移动文件Google Chrome for Testing.app/usr/local/chromedriver
  • 懒得空格转义,就把Google Chrome for Testing.app改名为chromedriver.app, 所以得到/usr/local/chromedriver/chromedriver.app
    • /usr/local/chromedriver/chromedriver.app/Contents/MacOS/Google Chrome for Testing.app也改名为
      chromedriver.app, , 所以得到/usr/local/chromedriver/chromedriver.app/Contents/MacOS/chromedriver
1
2
3
4
5
6
7
8
9
10
11
12
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

# 指定Chromedriver的路径
driver_path = '/usr/local/chromedriver/chromedriver.app/Contents/MacOS/chromedriver'

# 创建一个Chrome WebDriver实例
driver = webdriver.Chrome(executable_path=driver_path)

url = 'https://www.baidu.com'
driver.get(url)

这时候执行,chromedriver可以启动chrome窗口,但是无法打开页面’https://www.baidu.com’, 然后报错:

1
2
3
4
5
6
7
    driver = webdriver.Chrome(executable_path=driver_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/anaconda3/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "~/anaconda3/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /usr/local/chromedriver/chromedriver.app/Contents/MacOS/chromedriver

踩坑

“Google Chrome for Testing.app” is damaged and can’t be opened. You should move it to the Trash."

提示程序含有恶意代码或者已经打开所有来源还是提示扔到垃圾桶

Google Chrome for Testing.app官方解决方法: https://github.com/GoogleChromeLabs/chrome-for-testing#macos-says-the-app-is-damaged-what-now

在终端输入 sudo xattr -cr 'Google Chrome for Testing.app'

WebDriverManager setup failing to download chromedriver 116



show git comment