首页 > 解决方案 > 如何使目录路径相对,以便我们可以在 Mac 和 Windows 中运行代码

问题描述

我正在使用 Python 打开网络驱动程序。驱动程序路径是绝对的。如何使这个绝对路径动态化,以便我也可以在 Windows 上运行相同的代码?

from selenium import webdriver
driverpath="/Users/abhinavwadhankar/PycharmProjects/PythonAutomationFramework/Drivers/chromedriver-5"
driver = webdriver.Chrome(executable_path=driverpath)
driver.get("http://www.google.com")
print(driver.title)

标签: pythonseleniumselenium-webdriverfilepath

解决方案


推荐阅读