I unbale to interact with the edge browser on Azure portal in my web job which uses selenium automation

Ganesh Babar 0 Reputation points
2025-03-07T12:12:41.6933333+00:00

I have my web job deployed on Azure portal.

Web job has the Selenium script which will open the edge browser and interact with it to test my application.

When I run my job getting below error .


Starting Microsoft Edge WebDriver 133.0.3065.82 (e8aeaf3e01176b71fe9a899401d4da7cd0bcdf50) on port 50381
[03/07/2025 12:10:20 > 135f53: INFO] To submit feedback, report a bug, or suggest new features, please visit https://github.com/MicrosoftEdge/EdgeWebDriver
[03/07/2025 12:10:20 > 135f53: INFO] 
[03/07/2025 12:10:20 > 135f53: INFO] Only local connections are allowed.
[03/07/2025 12:10:20 > 135f53: INFO] Please see https://aka.ms/WebDriverSecurity for suggestions on keeping Microsoft Edge WebDriver safe.
[03/07/2025 12:10:20 > 135f53: INFO] 
[03/07/2025 12:10:21 > 135f53: INFO] msedgedriver was started successfully on port 50381.
[03/07/2025 12:10:35 > 135f53: INFO] Errors, Failures and Warnings
[03/07/2025 12:10:35 > 135f53: INFO] 
[03/07/2025 12:10:35 > 135f53: INFO] 
[03/07/2025 12:10:35 > 135f53: INFO] 1) Error : ConsoleApp1.Class1.Print()
[03/07/2025 12:10:35 > 135f53: INFO] System.InvalidOperationException : session not created: Microsoft Edge failed to start: crashed.
[03/07/2025 12:10:35 > 135f53: INFO]   (session not created: DevToolsActivePort file doesn't exist)
[03/07/2025 12:10:35 > 135f53: INFO]   (The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so msedgedriver is assuming that msedge has crashed.) (SessionNotCreated)
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,984 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2025-03-10T02:39:31.3633333+00:00

    Hi @Ganesh Babar ,

    Sounds same as a recent problem but no solution yet. A possible workaround for you is to add the argument --remote-debugging-port=9222 at EdgeOptions.

    To help the Dev Team troubleshoot the problem, you can provide more details in that thread, or create a new issue post at EdgeWebDriver Repo. Thanks for your understanding.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    Shijie Li

    0 comments No comments

  2. Bodapati Harish 820 Reputation points Microsoft External Staff Moderator
    2025-04-03T12:01:06.59+00:00

    Hello Ganesh Babar,

    To set up and deploy an Azure WebJob using Selenium WebDriver (Edge) with .NET 6, follow these steps carefully.

    First, install the required packages by running these commands in the Package Manager Console:

    Install-Package Selenium.WebDriver
    
    Install-Package Selenium.WebDriver.ChromeDriver
    
    Install-Package Microsoft.Edge.SeleniumTools
    

    Your project is targeting .NET 6. You can check this in your .csproj file. If it’s not set, update it like this:

    <PropertyGroup>
    
        <TargetFramework>net6.0</TargetFramework>
    
    </PropertyGroup>
    

    Next, download the Edge WebDriver from the official Microsoft site:

    Download Edge WebDriver

    Once downloaded, extract the file and place msedgedriver.exe inside your WebJob project under the Drivers folder: Drivers/msedgedriver.exe

    After placing the WebDriver file, go to Visual Studio and make sure to set its properties correctly:

    right click onmsedgedriver.exe file and update

    • Build Action: Content
    • Copy to Output Directory: Copy if newer

    Now, add the code for handling the queue trigger and automation using Selenium.

    Functions.cs

    
    using System;
    
    using System.IO;
    
    using Microsoft.Azure.WebJobs;
    
    using Microsoft.Extensions.Logging;
    
    using OpenQA.Selenium;
    
    using OpenQA.Selenium.Edge;
    
    namespace WebJob1
    
    {
    
        public class Functions
    
        {
    
            public static void ProcessQueueMessage([QueueTrigger("queue")] string message, ILogger logger)
    
            {
    
                logger.LogInformation($"[Queue Trigger Fired] Queue Message Received: {message}");
    
                RunEdgeAutomation(logger);
    
            }
    
            public static void RunEdgeAutomation(ILogger logger)
    
            {
    
                try
    
                {
    
                    string driverPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Drivers");
    
                    logger.LogInformation($"Computed Edge WebDriver path: {driverPath}");
    
                    var options = new EdgeOptions();
    
                    options.AddArgument("--headless");
    
                    options.AddArgument("--disable-gpu");
    
                    options.AddArgument("--no-sandbox");
    
                    options.AddArgument("--inprivate");
    
                    options.AddArgument("--remote-debugging-port=9222");
    
                    options.AddArgument("--disable-dev-shm-usage");
    
                    using (IWebDriver driver = new EdgeDriver(driverPath, options))
    
                    {
    
                        driver.Navigate().GoToUrl("https://en.wikipedia.org/wiki/Mahesh_Babu");
    
                        logger.LogInformation("Successfully navigated to the target URL");
    
                        var pageTitle = driver.Title;
    
                        logger.LogInformation($"Page Title: {pageTitle}");
    
                    }
    
                }
    
                catch (Exception ex)
    
                {
    
                    logger.LogError($"Edge WebDriver automation failed: {ex.Message}");
    
                }
    
            }
    
        }
    
    }
    
    

    Now, create the entry point for your Web Job inside Program.cs.

    Program.cs

    
    using System.Threading.Tasks;
    
    using Microsoft.Azure.WebJobs;
    
    using Microsoft.Extensions.Hosting;
    
    using Microsoft.Extensions.Logging;
    
    namespace WebJob1
    
    {
    
        internal class Program
    
        {
    
            static async Task Main(string[] args)
    
            {
    
                var host = CreateHostBuilder(args).Build();
    
                using (host)
    
                {
    
                    await host.RunAsync();
    
                }
    
            }
    
            static IHostBuilder CreateHostBuilder(string[] args) =>
    
                new HostBuilder()
    
                    .ConfigureWebJobs(b =>
    
                    {
    
                        b.AddAzureStorageCoreServices();
    
                        b.AddAzureStorageQueues();
    
                    })
    
                    .ConfigureLogging((context, loggingBuilder) =>
    
                    {
    
                        loggingBuilder.SetMinimumLevel(LogLevel.Error);
    
                        loggingBuilder.AddFilter("Function", LogLevel.Information);
    
                        loggingBuilder.AddFilter("Host", LogLevel.Debug);
    
                        loggingBuilder.AddConsole();
    
                    });
    
        }
    
    }
    
    

    After setting up the code, you need to configure your appsettings.json file. This file contains the connection string for Azure Storage.

    appsettings.json

    {
     "AzureWebJobsStorage":"DefaultEndpointsProtocol=https;AccountName=myaccountname;AccountKey=mykey;EndpointSuffix=core.windows.net"
    
    }
    

    Replace myaccountname and mykey with your actual Azure Storage Account details.

    Once everything is set up, you can run your WebJob locally. Just press F5 in Visual Studio and check the logs to see if the automation works as expected.

    When you are ready to deploy, right-click on your WebJob project in Solution Explorer, select Publish, and choose Azure App Service as your target. Follow the deployment steps, and once it’s published, check the logs in Azure to make sure everything is running fine.

    • When deploying to Azure, change your path to Azure. The sample Azure path will be like below:
    C:\home\site\wwwroot\app_data\Jobs\Triggered\WebJob1\Drivers
    

    For more details, please refer to this Stack Overflow post.

    I hope this help!


    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.