【发布时间】:2019-07-19 05:15:18
【问题描述】:
我使用过 .NetCore2 应用程序并尝试截取给定 URL 的屏幕截图。它在本地运行完美,但部署到 Azure 后创建 Webdriver 时出现问题。
at OpenQA.Selenium.DriverService..ctor(String servicePath, Int32 port, String driverServiceExecutableName, Uri driverServiceDownloadUrl)
↵ at OpenQA.Selenium.Chrome.ChromeDriverService..ctor(String executablePath, String executableFileName, Int32 port)
↵ at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
↵ at SceenshotApp.Service.Screenshot.TakeScreenshot(String url, Int32 width, Int32 height, Int32 delay) in D:\Projects\TFT\Bitbucket-Linkury\Website\Tools\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\Service\Screenshot.cs:line 21
↵ at SceenshotApp.Controllers.HomeController.TakeScreenshot(String url, Int32 width, Int32 height, Int32 scale, Int32 delay) in D:\Projects\TFT\Bitbucket-Linkury\Website\Tools\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\Controllers\HomeController.cs:line 51"
在我的代码下面
public static string GetScreenshot(string url)
{
ChromeOptions options = new ChromeOptions();
var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
driver.Manage().Window.Size = new System.Drawing.Size(1000, 768);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(100);
driver.Navigate().GoToUrl(url);
driver.Close();
driver.Quit();
return path;
}
如何在 Azure 上使用 Chrome 驱动程序?
【问题讨论】:
-
由于 azure web app 沙箱,azure web app 不支持 selenium。
-
@Ivan Yang : 谢谢回复,还有其他选择吗?
-
这不是一个好的解决方案,但如果部署到 azure vm 上它可以工作。
-
我的路径在 Nuget 包 Selenium.Chrome.WebDriver 下
-
@Dimitar :我正在使用 var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
标签: c# azure .net-core selenium-chromedriver azure-web-app-service