我正在使用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);
我有多个具有不同代理的配置文件。目前,浏览器启动了,对于第一个配置文件,一切都很好,但是一旦我处理浏览器并启动了一个具有新的配置文件和代理的新浏览器,驱动程序就会打开同一最后的浏览器。我尝试了许多解决方案,并且已将硒更改为旧版本,但没有运气。
我在控制台中注意到的一件事是,当驱动程序打开浏览器时,它会在这样的控制台上运行一个:
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"
如果我从命令中删除"从命令中删除",则看起来像这样
"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中开发(,但编程语言是 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;
}
它一定不能是静态的,因此您可以在参数中解析所需配置文件的名称。