Python Selenium Beta Chrome driver使用错误的二进制路径

3

我目前正在从Chrome 102切换到104 Beta(因为103对于我的Python - Selenium脚本使用情况有一个未修复的错误)。

我安装了Chrome Beta 104和104 Chrome驱动程序。当我启动脚本时,它会识别出它是一个104驱动程序,但驱动程序本身会在旧的Chrome路径中搜索chrome.exe应用程序:

它现在搜索的位置: C:\Program Files\Google\Chrome\Application\chrome.exe

它应该搜索的位置: C:\Program Files\Google\Chrome Beta\Application\chrome.exe

是否有一些简单的方法可以更改Beta Chrome驱动程序搜索exe的二进制路径?我可以在我的Python脚本中放置一些简单的内容。

1个回答

6
在这种情况下,你应该在Options类中使用binary_location指定selenium查找chrome执行程序的位置。
尝试使用以下代码:
假设你的chromedriver.exe文件和python文件在同一个文件夹中,否则你需要指定chromedriver.exe文件的路径。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

options = Options()
options.binary_location = r'C:\Program Files\Google\Chrome Beta\Application\chrome.exe'
browser = webdriver.Chrome(options = options, service = Service("chromedriver.exe"))

browser.get(your_url)

非常感谢,伙计。但是你写的路径前好像有个错别字:“r”。 - Mika Cammann
这被称为Rstring,它在字符串之前处理反斜杠作为普通字符,因此在处理文件路径时更好。 - Shodai Thox
啊,好的,知道了。抱歉,我是个新手哈哈。 - Mika Cammann
1
@MikaCammann 不用担心,我们都在这里学习些东西。 - Shodai Thox

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接