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

Selenium WebDriver报错:expected str, bytes or os.PathLike object, not Options 问题排查

Fixing "expected str, bytes or os.PathLike object, not Options" Error in Edge Selenium Setup

Hey there, let's break down why you're hitting this error and how to fix it quickly. The issue usually comes from either a missing driver path or outdated library compatibility issues.

Common Causes & Solutions

1. You Forgot to Specify the EdgeDriver Path

When you initialize webdriver.Edge(), if the EdgeDriver executable isn't in your system's PATH environment variable, the method expects you to pass the driver file path first—before the options parameter. Without this path, it misreads your Options object as the driver path, which triggers the error.

Fix:
Add the executable_path argument pointing to your local msedgedriver file (replace the example path with your actual file location):

from selenium import webdriver
from msedge.selenium_tools import EdgeOptions
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
from time import sleep

options = EdgeOptions()
options.use_chromium = True
options.headless = True
print('- Finish importing packages')
# Update this path to match your msedgedriver location
driver = webdriver.Edge(executable_path='C:/Users/YourName/Downloads/msedgedriver.exe', options=options)

Pro tip: Make sure your msedgedriver version exactly matches your installed Edge browser version—this avoids tons of weird compatibility bugs.

2. You're Using Outdated Library Tools (Selenium 4.x+)

If you're running Selenium 4.0 or newer, the msedge.selenium_tools library is no longer needed. Selenium now has native, built-in support for Edge Chromium, and mixing the old library with the new Selenium version causes type mismatches with the webdriver.Edge() method.

Fix:
Switch to Selenium's official EdgeOptions and ditch the deprecated library:

from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
from time import sleep

options = Options()
options.add_argument("--headless=new")  # Updated headless flag for modern Selenium
print('- Finish importing packages')
# If msedgedriver is in your system PATH, no need for executable_path here
driver = webdriver.Edge(options=options)

This uses Selenium's maintained, native Edge integration, which eliminates the type error right away.

Quick Final Checks

  • Double-check your executable_path for typos (even a small typo can break things)
  • Confirm your Edge browser and msedgedriver versions are identical—this is non-negotiable for smooth operation

内容的提问来源于stack exchange,提问作者hacking_mike

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 21:14:10