5

Is there a way to tell WebDriver in C# Selenium tests to open Chrome developer tool console, or some other way to get console to open while running Selenium tests without breaking them?
Or ability to programmatically read output to the console?
So far I have tried opening console manually (CTRL + SHIFT + I) while test is running, but that did break the test every-time.

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
  • 4
    The issue isn't Selenium but rather ChromeDriver. It requires the developer tools to be closed. https://code.google.com/p/chromedriver/issues/detail?id=483 ...so no. What do you intend to use them for? – Arran May 06 '14 at 14:45
  • @Arran Read debug messages. – Matas Vaitkevicius May 06 '14 at 14:53
  • 4
    You can access Chrome's console log programmatically. http://stackoverflow.com/questions/18261338/get-chromes-console-log/18283831#18283831 – Robbie Wareham May 06 '14 at 17:09
  • @RobbieWareham really helpful answer, to bad I am on .NET – Matas Vaitkevicius May 06 '14 at 17:27
  • It can be ported over to C#. I have ported it Ruby. The underlying chromedriver is the same. – Robbie Wareham May 06 '14 at 18:04
  • @LIUFAAccording to above comments it is not possible to open consele when tests are running, but at firefox it is. You can set the speed and check firefox developer tools. But if your issue only happens at chrome, it is better to follow RobbiWareham solution. – erhun Jul 02 '14 at 21:50

1 Answers1

4

To open chrome console:

var inSim = new WindowsInput.InputSimulator()

inSim.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.LCONTROL);
inSim.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.LSHIFT);
inSim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.VK_J);
inSim.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.LSHIFT);
inSim.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.LCONTROL);
  • What you can do: take a snapshot of the browser (including the opened console).
  • What you cannot do: use the webDriver (it will crash the test, but if you close the console, the same way you opened it, you will be able to continue)
  • Why: selenium needs an exclusive connection to DevTools.

Notice - some OS have strict input rules and might prevent the inputSimulator from working when the computer is locked or when you are running this code in a machine which has no keyboard connected to it (a server that is handled remotely)

hope this helps...

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
Avishay
  • 305
  • 1
  • 11
  • Can you explain what you mean by "What you cannot do: use the webDriver"? Are you saying you can close the console and then (and only then) continue with conventional Selenium testing code? – ruffin Jun 07 '16 at 14:48