[英]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.