Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Firefox使用selenium c打开错误的配置文件#_C#_Selenium_Selenium Webdriver_Geckodriver_Selenium Firefoxdriver - Fatal编程技术网

C# Firefox使用selenium c打开错误的配置文件#

C# Firefox使用selenium c打开错误的配置文件#,c#,selenium,selenium-webdriver,geckodriver,selenium-firefoxdriver,C#,Selenium,Selenium Webdriver,Geckodriver,Selenium Firefoxdriver,我将selenium 3.14与geckodriver 0.24结合使用,我将使用以下代码运行我已经为不同帐户创建的现有配置文件 FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.Proxy = pro; //my proxy object firefoxOptions.AddArgument("-profile " + path); //path to the profile FirefoxDriverSe

我将selenium 3.14与geckodriver 0.24结合使用,我将使用以下代码运行我已经为不同帐户创建的现有配置文件

FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.Proxy = pro; //my proxy object
firefoxOptions.AddArgument("-profile " + path); //path to the profile
FirefoxDriverService ffDriverService = FirefoxDriverService.CreateDefaultService();
ffDriverService.BrowserCommunicationPort = 2828;
PropertiesCollection.Driver = new FirefoxDriver(ffDriverService, firefoxOptions);
我有多个配置文件,每个配置文件都有不同的代理。现在,浏览器已经启动,第一个配置文件的所有功能都很好,但是一旦我处理了浏览器并使用新的配置文件和代理启动了一个新的浏览器,驱动程序就会打开最后一个相同的浏览器。我尝试了许多解决方案,并将selenium更改为旧版本,但运气不佳

我在控制台中注意到的一点是,当驱动程序打开浏览器时,它会在控制台上运行如下命令:

1561625708285   mozrunner::runner  INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile C:\\Users\\Usr\\Desktop\\fprofiles\\pf1" "-foreground" "-no-remote"
如果从cmd运行此命令,配置文件问题仍然存在:

"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile C:\\Users\\Usr\\Desktop\\fprofiles\\pf1" "-foreground" "-no-remote"
如果我删除“from”命令并使其成为完整文本,它将如下所示

"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" -marionette -profile C:\\Users\\Usr\\Desktop\\fprofiles\\pf1 -foreground -no-remote
我克隆了OpenQA的selenium项目并尝试在那里进行调试,但这也使用了geckodriver.exe,我猜geckodriver.exe负责获取参数并传递给firefox。 最后但最不重要的选择是,根据我的同意,再次编译geckodriver(已经编译过),但编程语言是RUST,要实现我所需要的,这将是一项长期的工作。
有人遇到过同样的问题吗?我如何修复它?

尝试根据浏览器配置文件的名称加载浏览器配置文件。一个名为“selenium_profile”的配置文件示例:

public static WebDriver driver;

public static String driverPath = "C:\\Users\\pburgr\\Desktop\\selenium-tests\\FF_driver_0_23\\geckodriver.exe";

public static WebDriver startFF() {
    FirefoxOptions options = new FirefoxOptions();
    ProfilesIni allProfiles = new ProfilesIni();         
    FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
    options.setProfile(selenium_profile);
    options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
    System.setProperty("webdriver.gecko.driver", driverPath);
    driver = new FirefoxDriver(options);
    driver.manage().window().maximize();
    return driver;
}

它不能是静态的,以便您可以在参数中分析所需配置文件的名称。

尝试根据其名称加载浏览器配置文件。一个名为“Seleniu_profile”的配置文件示例:

public static WebDriver driver;

public static String driverPath = "C:\\Users\\pburgr\\Desktop\\selenium-tests\\FF_driver_0_23\\geckodriver.exe";

public static WebDriver startFF() {
    FirefoxOptions options = new FirefoxOptions();
    ProfilesIni allProfiles = new ProfilesIni();         
    FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
    options.setProfile(selenium_profile);
    options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
    System.setProperty("webdriver.gecko.driver", driverPath);
    driver = new FirefoxDriver(options);
    driver.manage().window().maximize();
    return driver;
}
它不能是静态的,以便您可以在参数中分析所需配置文件的名称。

对于C#版本,尤其是.Net Core,请参阅:对于C#版本,尤其是.Net Core,请参阅:对于.Net Core C#:对于.Net Core C#: