Selenium C#-设置配置文件路径
我想使用存储在文件夹中的特定firefox配置文件 到目前为止,我的代码是:Selenium C#-设置配置文件路径,c#,selenium,firefox,geckodriver,C#,Selenium,Firefox,Geckodriver,我想使用存储在文件夹中的特定firefox配置文件 到目前为止,我的代码是: IWebDriver driver; string pathToCurrentUserProfiles = @"C:\FirefoxProfile\"; string[] pathsToProfiles = Directory.GetDirectories(pathToCurrentUserProfiles, "*.default"); FirefoxP
IWebDriver driver;
string pathToCurrentUserProfiles = @"C:\FirefoxProfile\";
string[] pathsToProfiles = Directory.GetDirectories(pathToCurrentUserProfiles, "*.default");
FirefoxProfile profile = new FirefoxProfile(pathsToProfiles[0]);
driver = new FirefoxDriver(profile);
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(10);
driver.Navigate().GoToUrl("https://localhost");
Visual Studio显示了以下错误:
Error CS1503 Argument 1: cannot convert from 'OpenQA.Selenium.Firefox.FirefoxProfile' to 'OpenQA.Selenium.Firefox.FirefoxOptions'
您需要创建FirefoxOptions对象并设置
Profile
属性:
FirefoxProfile profile=新的FirefoxProfile(路径文件[0]);
FirefoxOptions=新的FirefoxOptions()
{
外形=外形
};
驱动程序=新的Firefox驱动程序(选项);
您可以通过查看FirefoxDriver构造函数接受的参数来推断此解决方案。您需要创建FirefoxOptions对象并设置
配置文件属性:
FirefoxProfile profile=新的FirefoxProfile(路径文件[0]);
FirefoxOptions=新的FirefoxOptions()
{
外形=外形
};
驱动程序=新的Firefox驱动程序(选项);
您可以通过查看FirefoxDriver构造函数接受的参数来推断此解决方案。@Dominik:很抱歉。我发布了一些完全错误的代码。我更新了答案中的代码。@Dominik:很抱歉。我发布了一些完全错误的代码。我更新了答案中的代码。