【发布时间】:2021-10-26 20:56:47
【问题描述】:
我正在尝试连接到配置文件,它成功连接到自定义 Firefox 配置文件,但之后的问题是命令 FirefoxDriver driver = new FirefoxDriver(options);没有更多的作品,只有当我删除选项然后没有自定义配置文件时才有效。
最后一行返回错误 OpenQA.Selenium.WebDriverException: 'Process unexpectedly closed with status 0' 或 The HTTP request to the remote WebDriver timed out after 60 seconds, 只有当我删除 FirefoxDriver 中的选项时才有效:FirefoxDriver driver = new FirefoxDriver(options);
此外,执行 options.AddArgument("-profile" + "C:\Users\Chill\AppData\Roaming\Mozilla\Firefox\Profiles\5k2mdm2k.myprofile"); 而不是拆分 2 个参数不会在正确的配置文件中启动 Firefox。
甚至options.AddArgument("no-sandbox") 或options.AddArgument("-no-sandbox") 或options.AddArgument("--no-sandbox") 也不起作用,--profile 而不是-profile 也无法打开正确的配置文件,无论如何这是我的代码:
using System;
using OpenQA.Selenium; // nuget package name: Selenium.WebDriver
using OpenQA.Selenium.Firefox; // nuget package name: Selenium.WebDriver.GeckoDriver
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
FirefoxOptions options = new FirefoxOptions();
options.AddArgument("-profile");
options.AddArgument(@"C:\Users\Chill\AppData\Roaming\Mozilla\Firefox\Profiles\5k2mdm2k.myprofile"); /* type about:profiles in firefox bar to create and manage firefox profiles, from there you will see which profile used, make sure to not use the default one and use root directory */
FirefoxDriver driver = new FirefoxDriver(options); /* code stops here and puts error after closing browser or waiting until it close itself after 60 sec */
driver.Navigate().GoToUrl("https://www.google.com/"); /* can only reach this part of code if i remove turn FirefoxDriver(options); to FirefoxDriver(); on the line upper, but no more custom profile so */
}
}
}
希望你能帮助我在这一步被阻止 3 天
【问题讨论】:
标签: c# selenium selenium-webdriver selenium-firefoxdriver