问题描述
我正在尝试使用 Azure Function C# 代码中的 Selenium WebDriver.dll 并在实例化 WebDriver 时遇到以下问题.
i am trying to use Selenium WebDriver.dll from Azure Function C# code and having following issue when instantiating WebDriver.
错误:
2017-10-16T20:02:25.169 执行函数时出现异常:Functions.fnTestSelenium.Microsoft.Azure.WebJobs.Script:出现一个或多个错误.mscorlib:路径不是合法形式.2017-10-16T20:02:25.278 功能完成(失败,Id=2fcb928f-ee39-4cfe-99f2-4be2d57e91b2,持续时间=843ms)
2017-10-16T20:02:25.169 Exception while executing function: Functions.fnTestSelenium. Microsoft.Azure.WebJobs.Script: One or more errors occurred. mscorlib: The path is not of a legal form.2017-10-16T20:02:25.278 Function completed (Failure, Id=2fcb928f-ee39-4cfe-99f2-4be2d57e91b2, Duration=843ms)
代码
#r
"D:homesitewwwrootfnTestSeleniuminWebDriver.dll"使用 System.Net;
#r
"D:homesitewwwrootfnTestSeleniuminWebDriver.dll"
using System.Net;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
IWebDriver driver=new FirefoxDriver();
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
name = name ?? data?.name;
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
推荐答案
我认为在 Azure Functions 上运行 Selenium 不会有太大的成功.
I don't think you'll have much success running Selenium on Azure Functions.
Azure Functions,如 WebApp 和移动应用,在应用服务中运行.应用服务在称为沙盒的安全环境中运行,该环境具有一定的限制.其中,就是使用GDI+.
Azure Functions, like WebApps and Mobile Apps, run in an App Service. The App Service runs in a secure environment called a sandbox which imposes certain limitation. Amongst them, is the use of GDI+.
您可以查看限制列表以及不支持的框架列表 https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks
You can see the list of limitation, along with the list of unsupported frameworks https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks
如果你往底部检查,你会在不支持的列表中看到 Selenimum:
If you check towards the bottom, you will see Selenimum in the list of unsupported:
其他不支持的场景:
PhantomJS/Selenium:尝试连接到本地地址,也使用GDI+.
PhantomJS/Selenium: tries to connect to local address, and also uses GDI+.
这篇关于使用 Selenium WebDriver.dll 的 Azure 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!