Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you automatically open the Chrome Devtools tab within Selenium (C#)?

I see that there's a relatively new option to open Chrome with Devtools open from the command line, which I have gotten to work from my Windows 8.1 command line using a call like this:

c:\Program Files (x86)\Google\Chrome\Application>"chrome.exe" --auto-open-devtools-for-tabs

When I try to add this option on the same box when creating my ChromeDriver in Selenium (in C#), however, the option seems to be ignored.

var options = new ChromeOptions();
options.AddArgument("auto-open-devtools-for-tabs");

string executingAssembly = System.Reflection.Assembly.GetExecutingAssembly().Location;
string driverPath = Path.Combine(Path.GetDirectoryName(executingAssembly), "ChromeWebDriver");
_driver = new ChromeDriver(driverPath, options);

I've tried a few variations on theme to make sure options are working at all, including...

var options = new ChromeOptions();
options.AddArguments(new[] { "start-maximized", "auto-open-devtools-for-tabs"});

... and...

var options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("auto-open-devtools-for-tabs");

... and...

var options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddExcludedArgument("auto-open-devtools-for-tabs");

... as well as setting those with -- in front of each option string. All I get from any of those are maximized windows.

I get the feeling the auto-open-devtools-for-tabs argument's not supported by Selenium's Chrome Web Driver, but I'm not sure why that wouldn't support the same set of options as the "full" app.

Anyone have this option working with Selenium in C#, or know why it shouldn't be working in this case?


This is not unlike this question, but here I'm asking specifically about the auto-open-devtools-for-tabs option with C#. That asker claims not to have had any luck with options, and was asking how to open devtools from "within" Selenium, looking for a method explicitly before this option existed.

like image 270
ruffin Avatar asked Jun 07 '16 15:06

ruffin


1 Answers

I've tried this with in VS 2017, Selenium v3.12.1#, Firefox v60.0.2, Chrome v66, Nunit v3.10.1, Gecko Driver v20.1, and Chrome driver v2.4 (all using C#).

I tried to search for Firefox but did not have any success. I did find a solution for Chrome v66.

Please provide profile like this: options.AddArguments("--auto-open-devtools-for-tabs");

This is a complete chrome driver implementation:

ChromeOptions options = new ChromeOptions();
options.AddArgument("--start-maximized");
options.AddArguments("disable-infobars");
options.AddArguments("--disable-notifications");
options.AddArguments("--auto-open-devtools-for-tabs");
driver = new ChromeDriver(DrivePath, options, TimeSpan.FromSeconds(100));

See also this post: "List of Chromium Command Line Switches"

Below commands are NOT working, this is issue with Geckodriver so Gecko team has to provide some solution or fix for that:

driver.FindElement(By.CssSelector("body")).SendKeys(Keys.F12);

Actions action = new Actions(driver); action.SendKeys(Keys.F12); action.Perform();

Actions action = new Actions(driver); action .KeyDown(Keys.Control)
    .SendKeys(Keys.F12).KeyUp(Keys.Control).Perform();

Actions action = new Actions(driver); action.SendKeys(Keys.F12); action.Click();
like image 187
Mike ASP Avatar answered Sep 25 '22 19:09

Mike ASP