You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Playwright:如何在运行时获取浏览器可执行文件路径

获取Chromium可执行文件路径的实用方法

1. 自动化测试框架内直接获取(以Selenium为例)

如果你的测试基于Selenium开发,可通过两种方式获取路径:

  • 未启动驱动前获取默认路径
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
default_chromium_path = chrome_options.binary_location
  • 启动驱动后从实例提取
from selenium import webdriver

driver = webdriver.Chrome()
browser_exec_path = driver.binary_location

2. 系统命令直接查找

不同操作系统下用终端/命令行快速定位:

  • Windows(PowerShell):
Get-Command chromium | Select-Object -ExpandProperty Source
  • macOS(终端):
which chromium
# 若是Chrome Canary,执行:which google-chrome-canary
  • Linux(终端):
which chromium-browser

3. 测试配置预定义

在项目配置文件(如settings.py、config.yaml)中提前写死路径,测试初始化阶段直接调用:

# settings.py示例
CHROMIUM_PATH = "/usr/bin/chromium-browser"  # Linux
# Windows示例:"C:\\Program Files\\Chromium\\Application\\chrome.exe"

内容的提问来源于stack exchange,提问作者I.sh.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 21:53:10