gpt4 book ai didi

python - Selenium 无效参数异常

转载 作者:行者123 更新时间:2023-12-01 07:38:11 25 4
gpt4 key购买 nike

我创建了一个类作为 selenium 驱动程序的基本设置。当我运行它时,我收到一条名为“无效参数”的错误消息,我不知道该怎么办。

我认为这段代码中的元组“url”有错误。请帮助我。

SeleniumDriver 类: '''chromedriver(selenium) 的基本设置'''

def __init__(self, 
driversource='C:\\Users\Ewis\Downloads\chromedriver.exe',
url = ('https://realpython.com/')
):
self.driversource = driversource
self.url = url # this tuple

def __enter__(self):
self.driver = webdriver.Chrome(executable_path=self.driversource)
for urls in self.url:
self.driver.get(urls)
return self.driver, Keys

def __exit__(self, exc_type, exc_val, exc_trace):
self.driver.quit()

回溯(最近一次调用最后一次):

 File "<stdin>", line 1, in <module>
File "c:\python\progs\my_modules\seleniumdriver\seleniumdriver.py", line 16, in __enter__
resp = self.driver.get(urls)
File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: chrome=75.0.3770.100)

最佳答案

欢迎来到 Stackoverflow。可能的错误是您没有将元组作为 url 参数传递。正确的形式是

    def __init__(self, 
driversource='C:\\Users\Ewis\Downloads\chromedriver.exe',
url = ('https://realpython.com/', )
):
self.driversource = driversource
self.url = url # this tuple

如果没有几乎不明显的额外逗号,您的默认 url 参数只是带括号的字符串。

关于python - Selenium 无效参数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56874218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com