欢迎stackoverflow社区,
我正在尝试编译和运行这个网站上的程序代码:
我按照链接中列出的所有说明设置了我想要的路径。
程序和边缘驱动程序开始运行,但随后出现错误。
WebDriver.dll中出现错误异常"System.InvalidOperationException“。
进一步信息:未创建会话:找不到匹配的功能(SessionNotCreated)“
这是我的程序中的代码,或多或少是从上面的链接复制的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var anaheimService = ChromeDriverService.CreateDefaultService(@"C:\edgedriver_win64", "msedgedriver.exe");
// user need to pass the driver path here....
var anaheimOptions = new ChromeOptions
{
// user need to pass the location of new edge app here....
BinaryLocation = @"
C: \Program Files(x86)\Microsoft\Edge\Application\msedge.exe "
};
IWebDriver driver = new ChromeDriver(anaheimService, anaheimOptions); -- error appears at this line
driver.Navigate().GoToUrl("https: //google.com/");
Console.WriteLine(driver.Title.ToString());
driver.Close();
}
}
}
我真的很感谢你的帮助!
最好的问候Max
发布于 2021-11-23 02:40:54
你提到的那篇文章有点过时了。现在我们不需要使用ChromeDriver
来自动化边缘。有关如何使用WebDriver自动化Microsoft Edge的信息,请参阅official doc。
我推荐使用Selenium 4,这里我安装了Selenium 4.1.0 NuGet包,示例C#代码如下:
using System;
using OpenQA.Selenium.Edge;
namespace WebDriverTest
{
class Program
{
static void Main(string[] args)
{
var options = new EdgeOptions();
options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
var driver = new EdgeDriver(@"C:\edgedriver_win64", options);
driver.Navigate().GoToUrl("https://www.google.com");
Console.WriteLine(driver.Title.ToString());
driver.Close();
}
}
}
https://stackoverflow.com/questions/70062505
复制相似问题