TypeError:WebDriver.__init__() 获得意外的关键字参数“chrome_options”

问题描述 投票:0回答:1
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
driver = webdriver.Chrome(chrome_options=options, executable_path="C:/Utility/BrowserDrivers/chromedriver.exe", )
driver.get('http://google.com/')

上面是我的代码,但是当我尝试运行它时,我收到 chrome_options 错误。有人可以帮我解决这个问题吗?

python selenium-webdriver ui-automation chrome-options
1个回答
0
投票

webdriver.Chrome 构造函数不再具有 'chrome_options' 参数。 它已被弃用,现在您必须使用“options”参数。

这是 Chrome 类:

class WebDriver(ChromiumDriver):
"""Controls the ChromeDriver and allows you to drive the browser."""

def __init__(
    self,
    options: Options = None,
    service: Service = None,
    keep_alive: bool = True,
) -> None:
    """Creates a new instance of the chrome driver. Starts the service and
    then creates new instance of chrome driver.

    :Args:
     - options - this takes an instance of ChromeOptions
     - service - Service object for handling the browser driver if you need to pass extra details
     - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
    """
    self.service = service if service else Service()
    self.options = options if options else Options()
    self.keep_alive = keep_alive

    self.service.path = DriverFinder.get_path(self.service, self.options)

    super().__init__(
        DesiredCapabilities.CHROME["browserName"],
        "goog",
        self.options,
        self.service,
        self.keep_alive,
    )
© www.soinside.com 2019 - 2024. All rights reserved.