Is it possible to automatically open Google Chrome devtools?
Asked Answered
M

6

13

Given that Selenium 2 closes the devtools window which contains my emulator profile saved under my user profile for chrome. Is there a way to trigger devtools to open using a selenium script?

Here is the info on the devtools window closing issue https://sites.google.com/a/chromium.org/chromedriver/help/devtools-window-keeps-closing

I feel a little exhausted trying some of these Chromium override parameters only one of which seems to work http://peter.sh/experiments/chromium-command-line-switches/

The one that had any affect is the following

options.addArguments("user-data-dir=/Path/to/chrome/profile");

If there is no way to open the dev tools window or panel, is there a way to initialize the emulator?

Malmo answered 29/1, 2014 at 0:44 Comment(0)
M
2

at the terminal, type the following -

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --auto-open-devtools-for-tabs
Mechanics answered 15/11, 2017 at 18:25 Comment(1)
see also: #43910243Unhandled
B
0

You can use Robot class for same. It just going to help you to open dev-tools on any browser.

Use this code on the place you want to open dev-tools

    try{
        Robot robot=new Robot();
        robot.keyPress(KeyEvent.VK_F12);
        robot.keyRelease(KeyEvent.VK_F12);  
    }
    catch(Exception ex){
        System.out.println(ex.getMessage());
    }
Bernice answered 9/6, 2015 at 12:23 Comment(1)
Hi Shubham. Any idea how to capture the text from the console tab in the DEV tools?Rhoden
S
0

You can used below given code, it is working fine with FireFox just change the browser

public void open(String url) {
    driver.get(url);
    Actions action = new Actions(driver);
    String pressF12=Keys.chord(Keys.F12,"");
    driver.findElement(By.id("lst-ib")).sendKeys(pressF12);
}
Spongin answered 14/3, 2016 at 12:54 Comment(0)
H
0

As the same link you provided says, it's not possible to use ChromeDev tools with Selenium's ChromeDriver since 2.x. It's simply in direct conflict, you could use either one or the other.

The only way to perform a workaround is to pause all chrome driver interactivity, launch the DevTool's through some other automation framework such as Robots API, do whatever you need, and continue.

But I might think on what I need from dev tools, isn't there an alternative to what you need by providing Chrome with the proper configuration on launch? (loading a different profile, or loading an emulated device)

Heal answered 19/4, 2016 at 14:18 Comment(1)
As of Chrome 63 you can now use DevTools at the same time as Selenium. See Multi-client remote debugging support.Rout
E
0

Why do you need the chrome devtools anyway?

  • Is it for monitoring the network traffic? Why not usefirefoxdriver with firebug.xpi or browsermobproxy.
  • To open a page in emulated device's browser. This can be done with chrome, without opening the devtools.

WebDriver with chrome emulated browser

This is a code snippet that you can use to fire up chrome browser in a particular emulate version. Note the key thing here is the deviceName value, which should match as it is mentioned in the chrome browser of yours.

public static WebDriver MobileOpen()
{
    Map<String, String> mobileEmulation = new HashMap<String, String>();
    System.setProperty("webdriver.chrome.driver","path/to/chromedriver");
    mobileEmulation.put("deviceName", "Google Nexus 6");
    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    chromeOptions.put("mobileEmulation", mobileEmulation);

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    WebDriver driver = new ChromeDriver(capabilities);
    return driver;
}

Hope this helps.
Edit: I just saw it is a 3 years old post. The guy probably has found his way home. :P

Eruption answered 3/3, 2017 at 10:28 Comment(0)
R
-1

Have you tried the console API for your needs? It will allow you to invoke some dev-tool functions from inside JS.

Reinhart answered 2/6, 2014 at 12:21 Comment(2)
If your test script invokes the keystrokes [Ctrl+Shift+I] would that do the job?Millett
Selenium automates browsers. You key use is to open the devtools, but you won't be able to do anything with it,Reinhart

© 2022 - 2024 — McMap. All rights reserved.