【问题标题】:Selenium Remote Webdriver with remote profile带有远程配置文件的 Selenium Remote Webdriver
【发布时间】:2021-04-17 03:23:26
【问题描述】:

是否可以在服务器中打开具有特定远程配置文件(非临时)的 Selenium Remote Webdriver?

我只能从客户端传递browser_profile。如果我在没有browser_profile 的情况下实例化类,Selenium 会在服务器中创建一个新的临时配置文件。

from selenium import webdriver

class Remote(webdriver.Remote):
    def __init__(self, **kwargs):
        capabilities = {_**whatever_}

        super().__init__(
            command_executor='http://HOST:PORT/wd/hub',
            desired_capabilities=capabilities.copy(),
            browser_profile=webdriver.FirefoxProfile(_what?_)
        )

【问题讨论】:

  • 是的,你可以。您是否尝试过禁用服务器中的防火墙?
  • @Prabhakar 防火墙正在将端口转发到服务器。也许我的问题并不清楚。我已经编辑过了。
  • 您是否在您的机器中创建了 FireFox 配置文件?如果没有,请参考toolsqa.com/selenium-webdriver/custom-firefox-profile 并将配置文件添加到您的代码中,然后尝试
  • 我可以将配置文件我的机器传递到服务器并在服务器in中创建临时配置文件。但我想使用 of 服务器的配置文件。

标签: python selenium remotewebdriver


【解决方案1】:

不,在远程 webdriver 的情况下,无法传递远程配置文件的路径。原因是所有远程通信都由command executor 处理。 browser profile 仅处理本地文件系统。虽然默认配置文件可以是服务器上的configured

【讨论】:

  • 但是这个参数创建了配置文件的副本,它不使用实际的配置文件。我也试过-browserSessionReuse,但没有成功。有什么方法可以在测试之间启用会话持久性?
  • 有一种方法可以使用远程配置文件,另一种方法是拥有多个配置文件。我还没有完成的是能够通过选项、功能或 options.to_capabilities() 传递远程配置文件路径。所以,我最终得到了一个真正的 Firefox,带有自定义 -P 配置文件,启用了 -marionette,然后启动了带有全套标志的 geckodriver,-marionete--port 2828,--connect-existing 等。拥有多个配置文件的方法是使用一组配置文件和端口启动许多 Firefox 和 geckodrivers 实例。
  • 如果您有兴趣,我可以尽我所能详细说明一个正确的答案。我无法回答的是“如何使用远程驱动程序传递远程配置文件路径”,但我可以回答“使用特定远程配置文件(非临时)打开 Selenium Remote Webdriver”
  • @m3enda 我最终做了类似的事情并通过袜子挖隧道。这个问题似乎一直很受欢迎,所以如果你想详细说明答案,我很乐意接受。
【解决方案2】:

这就是我要找的东西:

            fp = webdriver.FirefoxProfile()
            fp.set_preference("browser.startup.homepage_override.mstone", "ignore")
            fp.set_preference("focusmanager.testmode", True)
            fp.update_preferences()

            driver = webdriver.Remote(
                command_executor='http://127.0.0.1:4444/wd/hub',
                desired_capabilities={'browserName': 'firefox', 'javascriptEnabled': True},
                browser_profile=fp
            )

参考:

【讨论】:

    猜你喜欢
    • 2012-10-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 2017-02-15
    • 2014-11-25
    • 1970-01-01
    相关资源
    最近更新 更多