使用 Selenium Web 驱动程序每个选项卡一个会话?

Lin*_*dau 5 python browser selenium python-3.x selenium-webdriver

我想为我打开的每个选项卡创建一个新会话,然后使用 Selenium python 单独控制会话。这可能吗?

kod*_*613 2

@reynoldsnp:Firefox 有一个官方插件可以做到这一点,但我不确定你是否可以让 selenium 与该插件交互。addons.mozilla.org/en-GB/firefox/addon/multi-account-containers 如果您找到一种方法来做到这一点,我很想知道如何做。

(由于我的声誉评分,我还无法发表评论,因此引用评论)。

我不知道如何与扩展程序实际交互,但如果您有一组已知的网站,您想打开:

尝试这个:

  1. 制作一个 Firefox 配置文件以供与 Selenium 一起使用。多个配置文件

    Windows 8/8.1/10:按键盘上的Win+ 。R类型firefox --new-instance --ProfileManager

  2. 通过在设置向导中选择新的配置文件,在该配置文件中打开 Firefox。在该配置文件中安装扩展。

选择配置文件顶部打开 Firefox

  1. 在扩展中设置您想要的容器,默认情况下,使用特定站点打开。

默认情况下使用容器打开站点 默认打开站点 确保选中该复选框。

  1. 使用该配置文件启动 selenium,如下所示:
from selenium import webdriver

profile = webdriver.FirefoxProfile('path/to/your/profile') # on windows found here: %APPDATA%/Mozilla/Firefox/Profiles

driver = webdriver.Firefox(firefox_profile=profile) 
Run Code Online (Sandbox Code Playgroud)
  1. 使用 selenuium 在选项卡(有效的容器)之间导航。