【问题标题】:TypeError: EnumMeta.__call__() missing 1 required positional argument: 'value'TypeError:EnumMeta.__call__() 缺少 1 个必需的位置参数:\'value\'
【发布时间】: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


【解决方案1】:

您导入了错误的导入。
代替

from ssl import Options

它应该是

from selenium.webdriver.chrome.options import Options

【讨论】:

  • 这行得通,虽然我是python新手,但还有一个问题。当我运行这个脚本时,它执行得很好,但是我看到进程仍在运行。我该如何结束或退出。一旦工作完成。
  • 这不是一个困难的问题,但这是另一个新问题。请接受此处给出的答案以表明该问题已解决,然后为此提出一个新问题
【解决方案2】:

为 chrome_options 添加自我。

并使用 from selenium.webdriver.chrome.options import Options not from ssl import Options

from selenium import webdriver
from webbrowser import Chrome
from selenium.webdriver.chrome.options 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=self.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()

【讨论】:

  • 是的,我知道我在这里复制它时错过了它,这不会解决问题。
  • 从 Selenium.webdriver.chrome.options 导入它确实有效。
猜你喜欢
  • 2020-12-05
  • 2021-09-12
  • 2022-06-22
  • 2014-09-13
  • 1970-01-01
  • 1970-01-01
  • 2019-10-10
  • 2017-03-27
相关资源
最近更新 更多