Search code examples
selenium-webdrivermicrosoft-edge-extensionselenium-edgedriver

Selenium edge driver cannot go to extension page using codes


I'm trying to use Selenium 4 to do some automation on extension of web browser. Currently, I just use it on Microsoft Edge driver. I found that I was unable to open any extension of Edge, Firefox or Chrome. (Using Vb.net)

Here's my code:

    Imports OpenQA.Selenium
    Imports OpenQA.Selenium.Edge
    Imports OpenQA.Selenium.Support.UI

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim options As New EdgeOptions()
            options.AddArgument("--user-data-
dir=C:\Users\jasonfan\AppData\Local\Microsoft\Edge\User Data")
            options.AddArgument("--no-sandbox")
            options.AddArgument("--remote-debugging-pipe")`
            options.AddArgument("--allow-running-insecure-content")
            options.AddArgument("--ignore-certificate-errors")

            Dim driver As IWebDriver = New EdgeDriver(options)

            driver.Navigate().GoToUrl("chrome-extension://odphnbhiddhdpoccbialllejaajemdio/options.html")

        End Sub
    End Class

In fact, when this was executed, that ("chrome-extension://odphnbhiddhdpoccbialllejaajemdio/options.html") will not be opened. But, I can go to that page manually without any problem. This means that extension path is correct. But, it doesn't work when using the code to open it automatically. Does anyone have any idea?

By the way, I'm currently using Windows 11 platform. Both my version of Microsoft Edge and WebDriver are 128.0.2739.42

Originally, when I try to navigate to a webpage using WebDriver, I get an ERR_BLOCKED_BY_CLIENT error, and the DevTools listening on ws://127.0.0.1:13787/devtools/browser/4f6b659e-9f69-4303-a63e-8cc8b91e44f6 error message.

I've tried ignoring certificate errors using the --ignore-certificate-errors argument, but it doesn't seem to work. I've also tried disabling DevTools and adjusting the log level, but the issue persists.

Until I add the following line of code, the error message gone: options.AddArgument("--remote-debugging-pipe")

But, my target is to turn on some functionality of an extension. So, I tried and tried again. It never worked.

Hope somebody can help.


Solution

  • The code works actually. Simply make sure you have killed all msedge.exe tasks before you run this project. You can either use task manager or taskkill /f /im msedge.exe in CMD to help you kill the remaining tasks.