【发布时间】:2022-11-10 02:48:21
【问题描述】:
我希望在脚本中将 webdriver 设置为无头。我能够以非无头方式运行它,但是当我创建 Option() 的实例时,它说我缺少 1 个必需的位置参数:'value'
chrome_options = Options()
这是我在项目中遇到的问题的复制。
from selenium import webdriver
from webbrowser import Chrome
from ssl import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class PythonOrg():
def Setup(self):
self.chrome_options = Options()
self.chrome_options.add_argument("--headless")
# self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) #not a headless
self.driver = webdriver.Chrome(options=chrome_options)
def GetLink(self):
driver = self.driver
driver.get('https://www.python.org')
print(driver.title)
driver.close()
inst = PythonOrg()
inst.Setup()
inst.GetLink()
注意:我是 Python 新手!
【问题讨论】:
-
您能否将回溯添加到问题中?
标签: python selenium-webdriver selenium-chromedriver ui-automation webautomation