Selenium webdriver 错误:“NoneType”对象没有属性“to_capability”

问题描述 投票:0回答:1

我尝试在 Python 上运行以下代码行,但抛出错误:

“[11] 中的单元格,第 10 行 驱动程序 = webdriver.Remote(service.service_url,选项)

文件〜/anaconda3/envs/algo/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:189在init 功能 = options.to_capability()

AttributeError:'NoneType'对象没有属性'to_capability'”

如果有人可以分享解决此问题的想法,将会非常有帮助!

代码:

    token_path = "api_key.txt"
    key_secret = open(token_path,'r').read().split()
    kite = KiteConnect(api_key = key_secret[0])
    service = webdriver.chrome.service.Service('./chromedriver')
    service.start()
    options = webdriver.ChromeOptions()
    options = options.to_capabilities()
    driver = webdriver.Remote(service.service_url,options)
    driver.get(kite.login_url())

python selenium-webdriver webdriver
1个回答
0
投票

你可以这样尝试

from selenium import webdriver

token_path = "api_key.txt"
key_secret = open(token_path, 'r').read().split()
kite = KiteConnect(api_key=key_secret[0])
options = webdriver.ChromeOptions()
service = webdriver.chrome.service.Service('./chromedriver')
service.start()
driver = webdriver.Remote(service.service_url, 
desired_capabilities=options.to_capabilities() if options else None)
driver.get(kite.login_url())
© www.soinside.com 2019 - 2024. All rights reserved.