Azure Function using Selenium WebDriver.dll

99封情书 提交于 2021-02-07 08:35:59

问题


i am trying to use Selenium WebDriver.dll from Azure Function C# code and having following issue when instantiating WebDriver.

Error:

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)

Code

#r "D:\home\site\wwwroot\fnTestSelenium\bin\WebDriver.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);
}

回答1:


I don't think you'll have much success running Selenium on Azure Functions.

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+.

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

If you check towards the bottom, you will see Selenimum in the list of unsupported:

Other scenarios that are not supported:

PhantomJS/Selenium: tries to connect to local address, and also uses GDI+.



来源:https://stackoverflow.com/questions/46778220/azure-function-using-selenium-webdriver-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!