我正在 Opera 瀏覽器上嘗試 selenium,但我不斷收到此錯誤。我嘗試過使用servicekwarg,但我一直在使用TypeError: WebDriver.__init__() got an unexpected keyword argument 'service'
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(r'path\to\operadriver.exe')
driver = webdriver.Opera(service)
uj5u.com熱心網友回復:
您可以從 WebDriver API 的檔案(https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.opera.webdriver)中看到這里:
__init__(executable_path=None, port=0, options=None, service_args=None, desired_capabilities=None, service_log_path=None, opera_options=None, keep_alive=True)
Creates a new instance of the operadriver.
Starts the service and then creates new instance of operadriver.
Args:
executable_path - path to the executable. If the default is used
it assumes the executable is in the $PATH
port - port you would like the service to run, if left as 0,
a free port will be found.
options: this takes an instance of OperaOptions
service_args - List of args to pass to the driver service
desired_capabilities: Dictionary object with non-browser specific
service_log_path - Where to log information from the driver.
opera_options - Deprecated argument for options capabilities only, such as “proxy” or “loggingPref”.
webdriver.Opera 沒有服務物件引數。
相反,您可以在此處查看此示例:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location ="<your opera executable directory>"
driver = webdriver.Opera(options=options)
driver.get("https://www.facebook.com")
# make sure 'operadriver.exe' is in the same folder as your directory
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/411720.html
標籤:
