Can anyone suggest the method to disable chromedriver logs getting generated on standard output in java, so that,
Starting ChromeDriver 2.32.498550
(9dec58e66c31bcc53a9ce3c7226f0c1c5810906a) on port 42936, only local
connections are allowed
will not appear on standard output.
I have already tried the below mentioned combinations, but none of them has worked:
ChromeOptions options = new ChromeOptions();
options.addArguments("--log-level=3");
options.addArguments("--disable-logging");
options.addArguments("--silent");
caps.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriverService service =new ChromeDriverService.Builder().withWhitelistedIps("").withVerbose(false).build();
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
System.setProperty("webdriver.chrome.logfile", "chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
Related
The bounty expires in 4 days. Answers to this question are eligible for a +50 reputation bounty.
arjun is looking for an answer from a reputable source.
I have been trying to set both the debuggerAddress and download directory options using chromedriver webdrivermanager (5.3.2) and selenium 4.8.0. Able to setup debuggerAddress option alone and works fine but when default_directory is used it gives error. Not sure if there is an option to set and use both. Any help or suggestions
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
String downloadFilepath = "/new";
HashMap<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.default_directory", downloadFilepath);
options.setExperimentalOption("prefs", prefs);
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
WebDriver driver = new ChromeDriver(options);
Error :
Could not start a new session. Response code 400. Message: invalid argument: entry 0 of 'firstMatch' is invalid
from invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: prefs
Host info: host: 'abc-UO2kkSNTJ', ip: ''
Build info: version: '4.8.0', revision: '267030adea'
System info: os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.6'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], debuggerAddress: 127.0.0.1:9222, extensions: [], prefs: {download.default_directory:
ew, profile.default_content_settings.popups: 0}}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], debuggerAddress: 127.0.0.1:9222, extensions: [], prefs: {download.default_directory:
ew, profile.default_content_settings.popups: 0}}}}]
The issue you are facing is because the debuggerAddress option and the download.default_directory option are not compatible with each other. When you set the debuggerAddress option, it starts a Chrome process with a remote debugging port, which means that the ChromeDriver can't control the Chrome instance anymore.
On the other hand, the download.default_directory option is used to set the default download directory for ChromeDriver to use. When you set this option, ChromeDriver sets a Chrome preference to save the downloaded files to the specified directory. However, this preference is set in the Chrome profile that ChromeDriver manages, which is not the same profile used by the remote debugging instance.
One way to work around this issue is to start a separate instance of Chrome using the --remote-debugging-port option and set the download directory for that instance. Here is an example code snippet that shows how to do this:
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
String downloadFilepath = "/new";
HashMap<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);
options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
Process process = Runtime.getRuntime().exec("google-chrome-stable --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-profile --no-first-run --no-default-browser-check --disable-popup-blocking");
ChromeDriver driver = new ChromeDriver(options);
driver.executeScript("window.open();");
driver.switchTo().window(driver.getWindowHandles().toArray()[1].toString());
driver.get("chrome://settings/content/downloads");
driver.executeScript("document.querySelector('settings-ui').shadowRoot.querySelector('#main').querySelector('settings-basic-page').shadowRoot.querySelector('#basicPage > settings-section.expanded > settings-privacy-page').shadowRoot.querySelector('settings-downloads-page').shadowRoot.querySelector('downloads-section').shadowRoot.querySelector('settings-toggle-button').click();");
driver.executeScript("document.querySelector('settings-ui').shadowRoot.querySelector('#main').querySelector('settings-basic-page').shadowRoot.querySelector('#basicPage > settings-section.expanded > settings-privacy-page').shadowRoot.querySelector('settings-downloads-page').shadowRoot.querySelector('#downloadPath').value='"+downloadFilepath+"';");
driver.executeScript("document.querySelector('settings-ui').shadowRoot.querySelector('#main').querySelector('settings-basic-page').shadowRoot.querySelector('#basicPage > settings-section.expanded > settings-privacy-page').shadowRoot.querySelector('settings-downloads-page').shadowRoot.querySelector('#downloadPath').dispatchEvent(new Event('input', {bubbles: true}));");
driver.switchTo().window(driver.getWindowHandles().toArray()[0].toString());
This code starts a separate Chrome instance with remote debugging enabled and sets the download directory for that instance using a series of JavaScript commands. It then switches back to the original Chrome instance and continues with the WebDriver automation. Note that this approach requires that you have Google Chrome installed on your system.
I hope this helps!
I have looked at the web search results and answers on stackoverflow on this topic but I couldn't find anyone having same issue. Following is code to enable performance logging that I am using:
ChromeOptions options = new ChromeOptions();
// options.addArguments("--headless");
options.addArguments("--remote-debugging-port=9222");
options.addArguments("--no-sandbox");
options.addArguments("--disable-application-cache");
options.addArguments("--disable-notifications");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-extensions");
options.addArguments("--test-type");
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
//options.addArguments("user-data-dir=C:\\apps\\selenium\\chrome\\data");
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
// add Network logging
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
Map<String, Object> perfLogPrefs = new HashMap<String, Object>();
perfLogPrefs.put("enableNetwork", true);
perfLogPrefs.put("traceCategories", "devtools.network");
options.setExperimentalOption("perfLoggingPrefs", perfLogPrefs);
webDriver = new ChromeDriver(options);
webDriver.manage().deleteAllCookies();
webDriver.manage().window().maximize();
When executed, it gives following error:
Starting ChromeDriver 80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987#{#185}) on port 27252
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
org.openqa.selenium.InvalidArgumentException: invalid argument: entry 0 of 'firstMatch' is invalid
from invalid argument: perfLoggingPrefs specified, but performance logging was not enabled
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03
What am I missing in above? The code examples use ChromeDriver(Capabilities) but that is deprecated. Is there some other setting that I need to enable before adding performance logging?
Thanks
I was able to find the answer on at SeleniumHQ issues. Essentially, CapabilityType.LOGGING_PREFS is broken in this version of ChromeDriver. I changed the line
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
to
options.setCapability("goog:loggingPrefs", logPrefs);
the preference name was changed to goog:loggingPrefs to be W3C compliant. I was able to collect network logs after this change.
Below driver works fine when i remove headless option but when i include it the test fails. Using chromedriver version 2.36.540470
public WebDriver createDriver() {
System.setProperty("webdriver.chrome.driver", "C:\\Dev\\tools\\chromedriver.exe");
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.addArguments("window-size=1900x1200");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--headless");
final WebDriver driver = new ChromeDriver(chromeOptions);
return driver;
}
Turns out chromedriver running headless does not deal with ssl certificates very well (current open issue with them). Switching to gecko driver fixed the issue.
As you can find at cannot stop Chrome from updating from 43 to 44 I am having problem with chrome 44, as RobW suggested (in comments) i got a stand alone chrome.exe which has the version that I need, but now I do not know how to connect it to my test application which is written by Selenium & JAVA.
You need to point the "binary" to your standalone Chrome using ChromeOptions:
ChromeOptions options = new ChromeOptions()
options.setBinary(new File("/path/to/chrome"));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
I am running selenium-server-standalone-2.17.0 (for IE and Firefox) and ChromeDriver 18.0.1022.0 (standalone) on a test box (Windows 7 64bit) which I use to run Java selenium tests against.
For some reason, when running my tests against ChromeDriver, the first time it encounters an unexpected Alert box, it blocks idefinitely and the ChromeDriver log says
WARNING: Executing: executeScript
I configured ChromeDriver using the guide http://code.google.com/p/selenium/wiki/ChromeDriver and set the timeout of all the drivers with
webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
Update:
I figured out how to initialize the remote ChromeDriver in a clean way with
URL url = new URL("http://192.168.1.15:4444/wd/hub");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Webdriver chromeDriver = new RemoteWebDriver(url, capabilities);
this ran best with the URL pointing to a selenium-server running chromedriver in a child process. You can make selenium-server run the ChromeDriver by starting it like this:
java -jar C:\selenium-server.jar -Dwebdriver.chrome.driver=C:\path\to\chromedriver.exe
I still have the same problem with Chrome getting stuck at the unexpected Alert box, but the selenium log gave me at bit more info:
INFO - Done: /session/1328623219287/element/253/click
INFO - Executing: [execute script: return !!document['readyState'];, []] at URL: /session/1328623219287/execute)
Still have no idea what is causing this... can anyone help?
This is how I initialize ChromeDriver:
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
"PathToWhereChromeDriverIsAvailable");
ChromeDriverService service = ChromeDriverService.createDefaultService();
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
ChromeDriver cd = new ChromeDriver(service, options);
With the Alert() i have just plain guess - probably it hangs out while executing the script - so basically you are not waiting for page to load, but for script to end executing. However, I do not have solution for this...