How to attach the Edge WebDriver to the running WebView2 app that is launched from a edge webdiver

E, Arun 0 Reputation points
2024-04-24T18:06:52.0233333+00:00

How can I attach the Edge WebDriver to a running WebView2 app that is launched from an Edge WebDriver?

I have a desktop application that has WebView2, and I can automate it by launching the UI app using WinAppDriver and attaching the Edge driver to the running WebView2 app via the remote debugging port.

However, in a special case where the desktop app launches from the Edge browser upon clicking a specific link,

I can launch the Edge browser and click the specific link using the Selenium Edge driver. The desktop application launches fine, but I'm unable to attach the Edge driver to the running WebView2 apps using the remote debugging port.

I don't see any URLs displayed in the localhost JSON list. Do you know if this works in such a case?

Note: the same approach works when the app is launched from the Selenium Chrome driver.

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,145 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ShiJieLi-MSFT 7,546 Reputation points Microsoft Vendor
    2024-04-25T07:15:08.7033333+00:00

    Hi @E, Arun,

    The best practice is only choosing one of the options:

    1. Letting Microsoft Edge WebDriver launch your WebView2 app
    2. Attaching Microsoft Edge WebDriver to a running WebView2 app

    Multiple Edge driver instances may cause conflicts. If you have to do so, after your first edge driver launches the desktop app from the specific link, just kill the first edge driver instance (Quit function may do this job). Only when the first edge driver has been killed should you try to attach another edge driver to the app.

    Theoretically it should work. But if it does not work or it is a bit complicated in your scenario, you should just launch the desktop app by other means (or even by Chrome driver), and then attach Edge driver to the app, which has been proved to work.


    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