【问题标题】:Selenium include firefox profile into DesiredCapabilities for Remote DriverSelenium 将 firefox 配置文件包含在远程驱动程序的 DesiredCapabilities 中
【发布时间】:2017-12-07 15:26:51
【问题描述】:

我的目标是在 Selenium Grid 的 Remore Webdriver 中使用以前保存的 FireFox 浏览器配置文件

我尝试将配置文件对象添加到DesiredCapabilities,但失败了,这是一个序列化错误。以下代码是我基于this JAVA code编写的:

desired_cap = {'acceptInsecureCerts': True, 'browserName': 'firefox',
           'marionette': True, 'browserstack.debug' : True}
profile_path= os.environ['APPDATA']+os.sep+os.path.join('Mozilla','Firefox','Profiles', 'rust_mozprofile.aaaabbbb')
profile_object = webdriver.FirefoxProfile(profile_path)
desired_cap['FirefoxDriver.PROFILE'] = profile_object

错误:...文件“C:\Python27\Lib\json__init__.py”,第 244 行,在 转储 返回 _default_encoder.encode(obj) 文件“C:\Python27\Lib\json\encoder.py”,第 207 行,编码 chunks = self.iterencode(o, _one_shot=True) 文件“C:\Python27\Lib\json\encoder.py”,第 270 行,在 iterencode return _iterencode(o, 0) File "C:\Python27\Lib\json\encoder.py",第 184 行,默认 raise TypeError(repr(o) + " is not JSON serializable") TypeError: is not JSON serializable

有什么建议吗? 是否有可能将 Firefox 配置文件传递给远程 Webdriver

【问题讨论】:

  • 您能考虑向我们更新您的确切用例吗?您是否尝试使用现有的 Firefox 配置文件?或者尝试创建一个新的 Firefox 配置文件?谢谢。
  • @DebanjanB,我尝试使用保存在文件夹 rust_mozprofile.aaaabbbb 中的现有 FireFox 配置文件。
  • 根据您的问题goal is to use a previously saved FireFox browser profile 检查我更新的答案。谢谢

标签: python selenium firefox selenium-grid


【解决方案1】:

我在本地加载配置文件:

    self.browser = webdriver.Firefox(
        firefox_profile=profile_object,
    )

还有远程。

self.browser = webdriver.Remote(
        command_executor=SELENIUM,
        browser_profile=profile_object,
        desired_capabilities= desired_cap
    )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-27
    • 2011-01-16
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 2012-08-29
    • 2018-04-19
    相关资源
    最近更新 更多