Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to open chrome browser console by pressing keyboard keys Ctrl+Shift+j in selenium webdriver. I am able to do this action using Robot class but I want this without Robot class. I have used the Actions class and Keys class using sendKeys. But I am unable to open browser console.

Is it chrome browser version issue or OS? Why the browser console is not opening using Action class and Keys class. ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
177 views
Welcome To Ask or Share your Answers For Others

1 Answer

To open chrome browser console you can use the ChromeOptions class with --auto-open-devtools-for-tabs argument as follows:

  • Test Configuration:

    • Selenium: Selenium Standalone Server v3.14.0
    • ChromeDriver: ChromeDriver 2.46.628402
    • Chrome: Google Chrome 72.0.3626.96
  • Code Block:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    
    public class A_Chrome_Browser_Console {
    
        public static void main(String[] args) {
    
            System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            options.addArguments("--disable-extensions");
            options.addArguments("--auto-open-devtools-for-tabs");
            WebDriver driver = new ChromeDriver(options);
            driver.get("https://www.google.com/");
            System.out.println(driver.getTitle());
        }
    }
    
  • Console Output:

    Google
    
  • Browser Console Snapshot:

chrome_browser_console

You can find a relevant based discussion in Opening inspect (pressing F12) on Chrome via Selenium


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...