繁体   English   中英

如何使用不同的 chrome 配置文件 C#、selenium webdriver 并行触发多个 chrome 实例

[英]How to trigger multiple chrome instances in parallel using different chrome profiles C#, selenium webdriver

我有下一个要求:

使用不同的 chrome 配置文件执行多个实例(并行)。 我有 3 个配置文件:profile1、profile2 和 profile3

当我创建驱动程序时,我添加了 profile1 的路径

对于并行运行,我如何告诉使用配置文件 2 的第二个实例

我发现了这个,我不知道如何并行执行。(我使用 Nunit 进行并行执行)

对不同的 ChromeDriver 实例使用相同的 chrome 配置文件(会话)

public static IWebDriver GetDriver()
     {
        var options = new ChromeOptions();
        options.AddArguments("--noerrdialogs");
        options.AddArguments(@"user-data-dir=C:\Users\" + loggedInUser + @"\AppData\Local\Google\Chrome\profile1");
        return new ChromeDriver(options); 
      }

好问题。我自己也在做同样的事情。 为了将 Selenium 指向正确的配置文件,到目前为止我有以下内容(不完整 - 但部分方式;认为有更好的方法;我无法打开具有相同可执行路径的驱动程序,但可以定义多个 chrome 驱动程序,这些驱动程序指向相同可执行文件,然后向其中的每一个添加带有单独配置文件的参数...(我使用的是 Python,您需要找出 Java 的等效项)。

从 selenium 导入 webdriver 从 selenium.webdriver.chrome.webdriver 导入 WebDriver

Options = webdriver.ChromeOptions() Profile_Path = "C:/Users//AppData/Local/Google/Chrome/User Data/Profile/" '''即相关配置文件的相关路径''' Options.add_argument('--用户数据目录 = = + Profile_Path)

'''我正在尝试使用 map 函数将 chromedrivers 列表传递给一个具有循环功能的函数,该循环执行如下操作:'''

定义设置(Number_Drivers):

v_profiles = []; v_options = []; v_chromedrivers =[]; v_drivers = []
profile_path = "C:/Users/..../User Data/Profile" 
'''put path of profile, noting this will become Profile1, Profile2, etc. below...'''

chromedrv_path = "C:/Users/... '''(i.e. path to chromedriver)'''
for i in range(Number_Drivers):
    v_profiles.append(profile_path + str(i) + "/")
    v_options.append(webdriver.ChromeOptions())
    v_chromedrivers.append(chromedrv_path)
    v_options[i].add_argument('--user-data-dir=' + v_profiles[i]



   ''' v_options[i].add_argument to be included for each other argument you want to 
       add, e.g. '--restore-last-session', '--disable-notifications', '--disable- 
       search-geolocation-disclosure' etc.)'''

v_drivers.append(webdriver.Chrome(executable_path=v_chromedrivers[i], options=v_options[i])

就我而言 - 祝你好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM