gpt4 book ai didi

selenium-webdriver - Selenium Remote Webdriver 给出 JSONDecodeError

转载 作者:行者123 更新时间:2023-12-01 05:00:26 34 4
gpt4 key购买 nike

我的代码:

import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common import desired_capabilities

class test_mycode(unittest.TestCase):
def setUp(self):
desired_cap = {'browser': 'IE', 'browser_version': '8.0', 'os': 'Windows', 'os_version': '7', 'resolution': '1366x768'}
self.driver = webdriver.Remote(command_executor='http://username:ACCESS_KEY@hub.browserstack.com:80/wd/hub', desired_capabilities=desired_cap)

def test_website(self):
.....

错误是:
Traceback (most recent call last):
File "C:\Workspace\Pumpkin Patch Website\test cases\_test_mycode.py", line 55, in setUp
desired_capabilities=desired_cap)
File "C:\Users\elton.tiong\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium-2.48.0-py3.5.egg\selenium\webdriver\remote\webdriver.py", line 87, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\elton.tiong\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium-2.48.0-py3.5.egg\selenium\webdriver\remote\webdriver.py", line 141, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Users\elton.tiong\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium-2.48.0-py3.5.egg\selenium\webdriver\remote\webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "C:\Users\elton.tiong\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium-2.48.0-py3.5.egg\selenium\webdriver\remote\errorhandler.py", line 102, in check_response
value = json.loads(value_json)
File "C:\Users\elton.tiong\AppData\Local\Programs\Python\Python35-32\lib\json\__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "C:\Users\elton.tiong\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\elton.tiong\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

selenium-server-standalone2.48.0 已安装并运行。

Python 是 3.5

这是我为在 Browserstack 上运行 Selenium 而编写的代码。我按照 Browserstack 给出的说明进行操作,但是,当我运行它时,它引发了 JSONDecodeError。

我还将 command_executor 更改为 http://127.0.0.1:4444/wd/hub但它失败了。然后我将desired_capabilities=desired_cap 更改为desired_capabilities.DesireCapabilities.FIREFOX 但它也失败了。

我到处搜索,但找不到任何答案。有人可以帮忙吗?非常感谢。

最佳答案

我知道这是 2 岁,但由于没有人回答,希望这对其他人有帮助。 desired_cap 中的值基本上是一个无效的json。为了确认,我针对 https://jsonlint.com/ 运行了它.

修复很简单 - 将所有单引号替换为双引号:

desired_cap = {'browser': 'IE', 'browser_version': '8.0', 'os': 'Windows', 'os_version': '7', 'resolution': '1366x768'}
desired_cap = desired_cap.replace('\\'', '\\"')

关于selenium-webdriver - Selenium Remote Webdriver 给出 JSONDecodeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33427246/

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