简体   繁体   English

C# 更改 selenium webdriver 中现有的 Firefox Profile 位置

[英]C# Changing the existing Firefox Profile location in selenium webdriver

I have created a new user profile( In Run, type -> firefox.exe -p and create a new profile ).我创建了一个新的用户配置文件( In Run, type -> firefox.exe -p and create a new profile )。 For demo purpose I have created a new folder on my desktop.出于演示目的,我在桌面上创建了一个新文件夹。 My new user profile points to this new location (C:\\Users\\username\\Desktop\\TemporaryProfile) .我的新用户配置文件指向这个新位置(C:\\Users\\username\\Desktop\\TemporaryProfile) In my selenium webdriver i want to change the default location of the firefox profile.在我的 selenium webdriver 中,我想更改 firefox 配置文件的默认位置。

FirefoxBinary binary = new FirefoxBinary(@"C:\Program Files (x86)\Mozilla   Firefox\firefox.exe");
  FirefoxProfile profile = new FirefoxProfile(@"C:\Users\username\Desktop\TemporaryProfile");                                
  FirefoxDriver driver = new FirefoxDriver(binary, profile);

In the preceding code, it is not taking the new firefox profile location rather it is taking the existing one.在前面的代码中,它没有采用新的 Firefox 配置文件位置,而是采用现有的位置。 I mean the default location.我的意思是默认位置。

And FireFoxProfile Class has a property named profileDirectory . FireFoxProfile类有一个名为profileDirectory的属性。 But unfortunately it is a get property但不幸的是它是一个 get 属性

public string ProfileDirectory { get; }

So I couldn't be able to set the directory location.所以我无法设置目录位置。

How to change the firefox profile location in selenium webdriver?如何更改 selenium webdriver 中的 Firefox 配置文件位置? Whenever my script executes it should not take the default profile location rather it should point to the new user profile location.每当我的脚本执行时,它不应采用默认配置文件位置,而应指向新的用户配置文件位置。 Can anyone tell me how to do this?谁能告诉我如何做到这一点?

This works for me to change profile:这适用于我更改个人资料:

var option = new FirefoxOptions();
var profile = new FirefoxProfile("Path_to_profile");
option.Profile = profile;
IWebDriver driver = new FirefoxDriver(option);

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

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