Selenium Python不能在chrome中使用选项。添加_参数(“headless”)

2024-10-04 03:23:52 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,伙计们

我正在尝试运行以下代码:

options = webdriver.ChromeOptions() 
options.add_argument("download.default_directory=C:\\Users\\gabriel.lucena\\Documents\\Python Scripts")
options.add_argument("--headless")
driver.get("xpage")

如果这个参数options.add_参数(“--headless”)被禁用,它们就会起作用


Tags: 代码adddefault参数downloadargumentusersdirectory
1条回答
网友
1楼 · 发布于 2024-10-04 03:23:52

驱动程序初始化在哪里。您需要在初始化驱动程序时传递chrome选项

options = webdriver.ChromeOptions()
options.add_argument("download.default_directory=C:\Users\gabriel.lucena\Documents\Python Scripts")
options.add_argument(" headless")
driver=webdriver.Chrome(options=options)

现在,如果您只是运行此代码来检查headless选项是否有效

driver.get("https://stackoverflow.com/")
print(driver.title)

相关问题 更多 >