question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Selenium 4] [C#] RemoteWebDriver doesn't implement IDevTools

See original GitHub issue

🐛 Bug Report

Description

When trying to get devtools for RemoteWebdriver as IDevTools, null returned. When instead of RemoteWebdriver using ChromeDriver, everything works fine and able to create dev tools session. Looks that RemoteWebDriver doesn’t implement IDevTools. https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/Remote/RemoteWebDriver.cs

To Reproduce

Doesn’t work - devTools are null var driver = new RemoteWebDriver(new Uri(_seleniumHubUrl), options.ToCapabilities(), TimeSpan.FromMinutes(2)); var devTools = driver as IDevTools; devTools.CreateDevToolsSession()

Works fine - devTools are not null var driver = new ChromeDriver(Environment.CurrentDirectory, options, TimeSpan.FromMinutes(3)); var devTools = driver as IDevTools; devTools.CreateDevToolsSession()

Expected behavior

RemoteWebDriver implements IDevTools. Able to set up dev tools and create dev tools session for RemoteWebdriver

Environment

OS: Windows10 Browser: Chrome Browser version: 87 Browser Driver version: 87.0.4280.8800 Language Bindings version: C# 4.0.0-alpha07 Selenium Grid version (if applicable): 4.0.0-beta-1-prerelease-20201208

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
szamaczcommented, Jan 13, 2021

I managed to have this working with some small workaround. Reviewing chromium driver code I found a method responsible for setting up chrome dev tools session and adjusted it a bit for my purpose.

First we need to set remote debugging address using chromeopitons. What is also important we need to run our driver in headless mode.

options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--remote-debugging-address=0.0.0.0");  // this is needed as by default it is set to localhost which allows only local connections
options.AddArgument("headless");

Then it can be used for setting up remote WebDriver dev tools session

var chromeCapabilities = driver.Capabilities.GetCapability("goog:chromeOptions") as Dictionary<string, object>;
if (chromeCapabilities == null) throw new Exception("Cannot get chromeOptions capabilities");
var debuggerAddress = chromeCapabilities["debuggerAddress"].ToString();
 private static DevToolsSession SetupRemoteChromeDevToolsSession(string debuggerAddress)
        {
            var devToolsSession = new DevToolsSession(debuggerAddress);

            //without that we are getting deadlock from xunit due to async code running in synchronous matter
            var task = Task.Factory.StartNew(() => devToolsSession.Start().ConfigureAwait(false).GetAwaiter().GetResult()); 
            Task.WaitAll(task);
            return devToolsSession;
        }

Of course for our selenium docker image, we need to expose the proper port so chrome dev tools session can be set up, in my case, it was standalone chome

docker run --privileged -d -p 4444:4444 -p 9222:9222 -v /dev/shm:/dev/shm selenium/standalone-chrome

2reactions
SKumar-777commented, Jan 13, 2021

Team,

I have tried to implement the devtools for RemoteWebdriver as IDevTools using C# and it returned null. It seems, the RemoteWebDriver does not implement IDevTools. We are waiting for this devtools support for RemoteWebdriver in Selenium 4. Thanks in advance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting up Chrome DevTools (Selenium 4) Using Remote ...
It seems that selenium doesn't use python's builtin async framework but uses a package called trio as well. You should be able to...
Read more >
Most Complete Selenium WebDriver 4.0 Overview
By casting a driver instance to IDevTools, users can now create sessions to use CDP calls for Chromium-based browsers. The DevTools API is...
Read more >
Selenium 4 with C# - Chrome DevTools Network Interception ...
In this video, we will discuss Selenium 4 Chrome DevTools Network Interception and how we ... Advanced Framework development Selenium C #: ...
Read more >
Change log - GitHub
The handling of sending and receiving data via WebSocket for use with Chrome ... The Selenium project does not check for the proper...
Read more >
Is it planned DevTools (CDP) to be used with ... - Google Groups
And RemoteWebDriver does not implemented this interface HasDevTools. ... Is it expected selenium4 to be released without CDP support for Selenium Grid ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found