【问题标题】:Selenium Python don't work in chrome using options.add_argument("--headless")Selenium Python 不能在 chrome 中使用 options.add_argument("--headless")
【发布时间】:2020-10-07 20:14:40
【问题描述】:

大家好,

我正在尝试运行此代码:

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_argument("--headless") 关闭,它们就会起作用

【问题讨论】:

  • 运行此代码 *

标签: python python-3.x selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

您的驱动程序初始化在哪里。您需要在初始化驱动程序时传递 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)

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

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

【讨论】:

    猜你喜欢
    • 2023-01-14
    • 1970-01-01
    • 2018-01-19
    • 2019-05-08
    • 2021-02-22
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 2021-11-08
    相关资源
    最近更新 更多