c# - 如何使用不同的 chrome 配置文件 C#、selenium webdriver 并行触发多个 chrome 实例
问题描述
我有下一个要求:
使用不同的 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);
}
解决方案
好 Q。我自己也在做同样的事情。为了将 Selenium 指向正确的配置文件,到目前为止,我有以下内容(不完整 - 但部分方法;认为有更好的方法;我无法打开具有相同可执行路径的驱动程序,但可以定义多个 chrome 驱动程序,pt. 相同可执行文件,然后将带有单独配置文件的参数添加到每个参数......(我使用的是 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 列表传递给一个带有循环的函数,该循环执行如下操作:'''
def 设置(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])
就我而言 - 祝你好运!
推荐阅读
- u-boot - 如何检查大型命令文本答案是否包含特定字符串
- python - Keras Custom Layer ValueError:一个操作对渐变有“无”
- android - 在多个 RecyclerViews 之间正确交换项目
- docker - 在 Nginx 后面运行 Docker Engine API
- ruby-on-rails - Rails 使一些路线资源单数和一些复数
- matlab - 匿名函数是否支持可选参数?
- python - if 语句的语法
- java - 为什么会抛出 java.util.InputMismatchException?
- xamarin - App Center 推送通知限制为 500 条消息
- c# - SAML 与 ASP.NET Core 身份的集成