我们使用Azure Cloud服务来托管MVC应用程序,该应用程序为客户端数据中的管理功能提供UI.希望从应用程序托管Selenium自动化.
当我在项目中捆绑ChromeDriver时,以下代码在Azure模拟器中本地运行:
public SeleniumService(string username, string password, string path)
{
Username = username;
Password = password;
var driverPath = Path.Combine(new string[] { path, "driver" });
driver = new ChromeDriver(driverPath);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(Timeout));
}
Run Code Online (Sandbox Code Playgroud)
但是当我从Azure运行时,Selenium也需要Chrome二进制文件.我将二进制文件打包在项目目录中,如果我在ChromeOptions中指定二进制路径...
public SeleniumService(string username, string password, string path)
{
Username = username;
Password = password;
var driverPath = Path.Combine(new string[] { path, "driver" });
ChromeOptions options = new ChromeOptions()
{
BinaryLocation = Path.Combine(new string[] { path, "binary" })
};
driver = new ChromeDriver(driverPath,options);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(Timeout));
}
Run Code Online (Sandbox Code Playgroud)
...我收到一个错误:
未知错误:chrome无法启动(驱动程序信息:chromedriver = …