Ubuntu系统下使用Selenium 4.11.2无法启动Edge浏览器求助
解决Selenium启动Edge浏览器却打开Chrome的问题
- 检查系统环境变量,确认未将ChromeDriver路径设为全局默认,避免Selenium优先读取错误的驱动路径。
- 显式指定Edge浏览器的二进制路径,强制Selenium调用Edge:
from selenium import webdriver from selenium.webdriver.edge.options import Options from os.path import join, expanduser HOME = expanduser("~") edgedriver = join(HOME, "webdrivers", "msedgedriver") edge_options = Options() # 根据系统替换为Edge实际安装路径 # Windows示例:edge_options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe" # macOS示例:edge_options.binary_location = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" edge_options.binary_location = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" service = webdriver.EdgeService(executable_path=edgedriver) driver = webdriver.Edge(service=service, options=edge_options) driver.get("https://google.com") - 重启终端或IDE,清除可能残留的Selenium配置缓存或旧驱动进程。
- Linux/macOS系统下,确保msedgedriver有执行权限,执行命令:
chmod +x /path/to/msedgedriver
内容的提问来源于stack exchange,提问作者PKlumpp
相关产品推荐
相关产品推荐

