How to programmatically disable Cloud Print “New Printer on your network” popup for Selenium...












0















How do you programmatically disable Chrome's Cloud Print "New printer on your network" popup when configuring ChromeDriver options for Selenium?



Whenever ChromeDriver starts up, a Cloud Print popup appears within a couple of seconds.



Cloud Print Chrome popup



It's possible to disable the Cloud Print popup for a normal Chrome user by turning it off in chrome://settings.



Chrome settings to disable the cloud print popup



AFAIK this disables it for the Chrome Profile, but that doesn't work for Selenium since every new driver instance has a clean slate profile. Also, I don't want to do UI automation to turn this off for every new driver instance, I'd rather just let the popup appear at that point (too much added complexity and room for failure for the tradeoff).



Using ChromeOptions.setExperimentalOption("prefs", prefs)



I have attempted to use Chromium's ChromeDriver documentation on Setting a Chrome Preference to set various preferences in order to turn off cloud print.



Here's the given example on how to set set a Chrome preference



ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);


None of the Chrome Switches (more switches) look like they will do the trick of disabling the popup, but some of the Chrome Preferences look like they might work.



// Enable notifications for new devices on the local network that can be
// registered to the user's account, e.g. Google Cloud Print printers.
const char kLocalDiscoveryNotificationsEnabled = "local_discovery.notifications_enabled";

// *************** SERVICE PREFS ***************
// These are attached to the service process.

// ...

const char kCloudPrintProxyEnabled = "cloud_print.enabled";


So let's try using these:



ChromeOptions options = new ChromeOptions();

final Map<String, Object> prefs = new HashMap<>();
prefs.put("local_discovery.notifications_enabled", 0);
prefs.put("cloud_print.enabled", 0);
options.setExperimentalOption("prefs", prefs);

return new ChromeDriver(options);


Attempting to use these preferences, however, doesn't work when providing 0 as shown in the Chromium ChromeDriver docs page.




NOTE: When I used "false" instead of 0, I could no longer reproduce the cloud printer popup, but then again, I couldn't reproduce the problem (force it) like I could earlier by toggling the setting on my normal non-driver browser. Using the string "false" might be the answer but until I can confirm by flipping in between the two, I won't believe it and I'm chalking it up to network printer hijinks while I'm writing this question.




I feel like this is the closest I've gotten to the solution, and everything else is just guesswork and exploration.



EDIT: After isolating the preference change as suggested in this (very sensible) SO answer, the diff showed:



<     "notifications_enabled": true
---
> "notifications_enabled": false


which, when followed to it's actual line/value in the JSON looks like:



"local_discovery": {
"notifications_enabled": true


which makes it seem like prefs.put("local_discovery.notifications_enabled", 0); is exactly what we're looking for! Now the final trick is to get it nailed down and reproducibly enabling/disabling the popup based on true/false inputs... so close!



Other Possible Leads or Alternatives (but probably just dead ends)



I do have an another idea/backup plan for how to deal with this: if it's not possible to disable the popup programmatically through Chrome preferences, I was thinking that creating a Chrome Profile with the Cloud Print setting turned off and sharing it between tests could work, since ChromeDriver appears to have a command line flag/argument to set the profile directory. It would just be so much easier if we could just use the Chrome preferences properly though.





I also have some auxiliary questions that would make this easier, please comment if you know what to do about any of these:




  1. Is there any way for me to tell that setting the ExperimentalOption preferences is doing anything? Is there a Hello World preference of some kind that would be easy to see the difference?

  2. Am I looking in the right place for the preference names? Is this Chromium Source file the right place to look? Is there any easier place for me to find preference names?

  3. What's the easiest way to make the Cloud Print think that there's a printer on the network? At some point I lost whatever printer was causing the popup and that's made it impossible to test/reproduce the problem/solution. If I can verify, I can close this question and post the answer.




Shout out to Selenium.Chrome where can I find a list of all available ChromeOption arguments? C# for being the only search result on Google or SO which pointed me to the Chrome Preferences. I wish there were better documentation for this...










share|improve this question




















  • 1





    If the notification setting is saved in some browser profile, just use the profile in selenium. System.setProperty("webdriver.chrome.driver", chromedriver_path); ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=" + "C:\Users\pburgr\AppData\Local\Google\Chrome\User Data"); driver = new ChromeDriver(options);

    – pburgr
    Nov 30 '18 at 11:01


















0















How do you programmatically disable Chrome's Cloud Print "New printer on your network" popup when configuring ChromeDriver options for Selenium?



Whenever ChromeDriver starts up, a Cloud Print popup appears within a couple of seconds.



Cloud Print Chrome popup



It's possible to disable the Cloud Print popup for a normal Chrome user by turning it off in chrome://settings.



Chrome settings to disable the cloud print popup



AFAIK this disables it for the Chrome Profile, but that doesn't work for Selenium since every new driver instance has a clean slate profile. Also, I don't want to do UI automation to turn this off for every new driver instance, I'd rather just let the popup appear at that point (too much added complexity and room for failure for the tradeoff).



Using ChromeOptions.setExperimentalOption("prefs", prefs)



I have attempted to use Chromium's ChromeDriver documentation on Setting a Chrome Preference to set various preferences in order to turn off cloud print.



Here's the given example on how to set set a Chrome preference



ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);


None of the Chrome Switches (more switches) look like they will do the trick of disabling the popup, but some of the Chrome Preferences look like they might work.



// Enable notifications for new devices on the local network that can be
// registered to the user's account, e.g. Google Cloud Print printers.
const char kLocalDiscoveryNotificationsEnabled = "local_discovery.notifications_enabled";

// *************** SERVICE PREFS ***************
// These are attached to the service process.

// ...

const char kCloudPrintProxyEnabled = "cloud_print.enabled";


So let's try using these:



ChromeOptions options = new ChromeOptions();

final Map<String, Object> prefs = new HashMap<>();
prefs.put("local_discovery.notifications_enabled", 0);
prefs.put("cloud_print.enabled", 0);
options.setExperimentalOption("prefs", prefs);

return new ChromeDriver(options);


Attempting to use these preferences, however, doesn't work when providing 0 as shown in the Chromium ChromeDriver docs page.




NOTE: When I used "false" instead of 0, I could no longer reproduce the cloud printer popup, but then again, I couldn't reproduce the problem (force it) like I could earlier by toggling the setting on my normal non-driver browser. Using the string "false" might be the answer but until I can confirm by flipping in between the two, I won't believe it and I'm chalking it up to network printer hijinks while I'm writing this question.




I feel like this is the closest I've gotten to the solution, and everything else is just guesswork and exploration.



EDIT: After isolating the preference change as suggested in this (very sensible) SO answer, the diff showed:



<     "notifications_enabled": true
---
> "notifications_enabled": false


which, when followed to it's actual line/value in the JSON looks like:



"local_discovery": {
"notifications_enabled": true


which makes it seem like prefs.put("local_discovery.notifications_enabled", 0); is exactly what we're looking for! Now the final trick is to get it nailed down and reproducibly enabling/disabling the popup based on true/false inputs... so close!



Other Possible Leads or Alternatives (but probably just dead ends)



I do have an another idea/backup plan for how to deal with this: if it's not possible to disable the popup programmatically through Chrome preferences, I was thinking that creating a Chrome Profile with the Cloud Print setting turned off and sharing it between tests could work, since ChromeDriver appears to have a command line flag/argument to set the profile directory. It would just be so much easier if we could just use the Chrome preferences properly though.





I also have some auxiliary questions that would make this easier, please comment if you know what to do about any of these:




  1. Is there any way for me to tell that setting the ExperimentalOption preferences is doing anything? Is there a Hello World preference of some kind that would be easy to see the difference?

  2. Am I looking in the right place for the preference names? Is this Chromium Source file the right place to look? Is there any easier place for me to find preference names?

  3. What's the easiest way to make the Cloud Print think that there's a printer on the network? At some point I lost whatever printer was causing the popup and that's made it impossible to test/reproduce the problem/solution. If I can verify, I can close this question and post the answer.




Shout out to Selenium.Chrome where can I find a list of all available ChromeOption arguments? C# for being the only search result on Google or SO which pointed me to the Chrome Preferences. I wish there were better documentation for this...










share|improve this question




















  • 1





    If the notification setting is saved in some browser profile, just use the profile in selenium. System.setProperty("webdriver.chrome.driver", chromedriver_path); ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=" + "C:\Users\pburgr\AppData\Local\Google\Chrome\User Data"); driver = new ChromeDriver(options);

    – pburgr
    Nov 30 '18 at 11:01
















0












0








0








How do you programmatically disable Chrome's Cloud Print "New printer on your network" popup when configuring ChromeDriver options for Selenium?



Whenever ChromeDriver starts up, a Cloud Print popup appears within a couple of seconds.



Cloud Print Chrome popup



It's possible to disable the Cloud Print popup for a normal Chrome user by turning it off in chrome://settings.



Chrome settings to disable the cloud print popup



AFAIK this disables it for the Chrome Profile, but that doesn't work for Selenium since every new driver instance has a clean slate profile. Also, I don't want to do UI automation to turn this off for every new driver instance, I'd rather just let the popup appear at that point (too much added complexity and room for failure for the tradeoff).



Using ChromeOptions.setExperimentalOption("prefs", prefs)



I have attempted to use Chromium's ChromeDriver documentation on Setting a Chrome Preference to set various preferences in order to turn off cloud print.



Here's the given example on how to set set a Chrome preference



ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);


None of the Chrome Switches (more switches) look like they will do the trick of disabling the popup, but some of the Chrome Preferences look like they might work.



// Enable notifications for new devices on the local network that can be
// registered to the user's account, e.g. Google Cloud Print printers.
const char kLocalDiscoveryNotificationsEnabled = "local_discovery.notifications_enabled";

// *************** SERVICE PREFS ***************
// These are attached to the service process.

// ...

const char kCloudPrintProxyEnabled = "cloud_print.enabled";


So let's try using these:



ChromeOptions options = new ChromeOptions();

final Map<String, Object> prefs = new HashMap<>();
prefs.put("local_discovery.notifications_enabled", 0);
prefs.put("cloud_print.enabled", 0);
options.setExperimentalOption("prefs", prefs);

return new ChromeDriver(options);


Attempting to use these preferences, however, doesn't work when providing 0 as shown in the Chromium ChromeDriver docs page.




NOTE: When I used "false" instead of 0, I could no longer reproduce the cloud printer popup, but then again, I couldn't reproduce the problem (force it) like I could earlier by toggling the setting on my normal non-driver browser. Using the string "false" might be the answer but until I can confirm by flipping in between the two, I won't believe it and I'm chalking it up to network printer hijinks while I'm writing this question.




I feel like this is the closest I've gotten to the solution, and everything else is just guesswork and exploration.



EDIT: After isolating the preference change as suggested in this (very sensible) SO answer, the diff showed:



<     "notifications_enabled": true
---
> "notifications_enabled": false


which, when followed to it's actual line/value in the JSON looks like:



"local_discovery": {
"notifications_enabled": true


which makes it seem like prefs.put("local_discovery.notifications_enabled", 0); is exactly what we're looking for! Now the final trick is to get it nailed down and reproducibly enabling/disabling the popup based on true/false inputs... so close!



Other Possible Leads or Alternatives (but probably just dead ends)



I do have an another idea/backup plan for how to deal with this: if it's not possible to disable the popup programmatically through Chrome preferences, I was thinking that creating a Chrome Profile with the Cloud Print setting turned off and sharing it between tests could work, since ChromeDriver appears to have a command line flag/argument to set the profile directory. It would just be so much easier if we could just use the Chrome preferences properly though.





I also have some auxiliary questions that would make this easier, please comment if you know what to do about any of these:




  1. Is there any way for me to tell that setting the ExperimentalOption preferences is doing anything? Is there a Hello World preference of some kind that would be easy to see the difference?

  2. Am I looking in the right place for the preference names? Is this Chromium Source file the right place to look? Is there any easier place for me to find preference names?

  3. What's the easiest way to make the Cloud Print think that there's a printer on the network? At some point I lost whatever printer was causing the popup and that's made it impossible to test/reproduce the problem/solution. If I can verify, I can close this question and post the answer.




Shout out to Selenium.Chrome where can I find a list of all available ChromeOption arguments? C# for being the only search result on Google or SO which pointed me to the Chrome Preferences. I wish there were better documentation for this...










share|improve this question
















How do you programmatically disable Chrome's Cloud Print "New printer on your network" popup when configuring ChromeDriver options for Selenium?



Whenever ChromeDriver starts up, a Cloud Print popup appears within a couple of seconds.



Cloud Print Chrome popup



It's possible to disable the Cloud Print popup for a normal Chrome user by turning it off in chrome://settings.



Chrome settings to disable the cloud print popup



AFAIK this disables it for the Chrome Profile, but that doesn't work for Selenium since every new driver instance has a clean slate profile. Also, I don't want to do UI automation to turn this off for every new driver instance, I'd rather just let the popup appear at that point (too much added complexity and room for failure for the tradeoff).



Using ChromeOptions.setExperimentalOption("prefs", prefs)



I have attempted to use Chromium's ChromeDriver documentation on Setting a Chrome Preference to set various preferences in order to turn off cloud print.



Here's the given example on how to set set a Chrome preference



ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);


None of the Chrome Switches (more switches) look like they will do the trick of disabling the popup, but some of the Chrome Preferences look like they might work.



// Enable notifications for new devices on the local network that can be
// registered to the user's account, e.g. Google Cloud Print printers.
const char kLocalDiscoveryNotificationsEnabled = "local_discovery.notifications_enabled";

// *************** SERVICE PREFS ***************
// These are attached to the service process.

// ...

const char kCloudPrintProxyEnabled = "cloud_print.enabled";


So let's try using these:



ChromeOptions options = new ChromeOptions();

final Map<String, Object> prefs = new HashMap<>();
prefs.put("local_discovery.notifications_enabled", 0);
prefs.put("cloud_print.enabled", 0);
options.setExperimentalOption("prefs", prefs);

return new ChromeDriver(options);


Attempting to use these preferences, however, doesn't work when providing 0 as shown in the Chromium ChromeDriver docs page.




NOTE: When I used "false" instead of 0, I could no longer reproduce the cloud printer popup, but then again, I couldn't reproduce the problem (force it) like I could earlier by toggling the setting on my normal non-driver browser. Using the string "false" might be the answer but until I can confirm by flipping in between the two, I won't believe it and I'm chalking it up to network printer hijinks while I'm writing this question.




I feel like this is the closest I've gotten to the solution, and everything else is just guesswork and exploration.



EDIT: After isolating the preference change as suggested in this (very sensible) SO answer, the diff showed:



<     "notifications_enabled": true
---
> "notifications_enabled": false


which, when followed to it's actual line/value in the JSON looks like:



"local_discovery": {
"notifications_enabled": true


which makes it seem like prefs.put("local_discovery.notifications_enabled", 0); is exactly what we're looking for! Now the final trick is to get it nailed down and reproducibly enabling/disabling the popup based on true/false inputs... so close!



Other Possible Leads or Alternatives (but probably just dead ends)



I do have an another idea/backup plan for how to deal with this: if it's not possible to disable the popup programmatically through Chrome preferences, I was thinking that creating a Chrome Profile with the Cloud Print setting turned off and sharing it between tests could work, since ChromeDriver appears to have a command line flag/argument to set the profile directory. It would just be so much easier if we could just use the Chrome preferences properly though.





I also have some auxiliary questions that would make this easier, please comment if you know what to do about any of these:




  1. Is there any way for me to tell that setting the ExperimentalOption preferences is doing anything? Is there a Hello World preference of some kind that would be easy to see the difference?

  2. Am I looking in the right place for the preference names? Is this Chromium Source file the right place to look? Is there any easier place for me to find preference names?

  3. What's the easiest way to make the Cloud Print think that there's a printer on the network? At some point I lost whatever printer was causing the popup and that's made it impossible to test/reproduce the problem/solution. If I can verify, I can close this question and post the answer.




Shout out to Selenium.Chrome where can I find a list of all available ChromeOption arguments? C# for being the only search result on Google or SO which pointed me to the Chrome Preferences. I wish there were better documentation for this...







java selenium google-chrome selenium-chromedriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 0:03







George Pantazes

















asked Nov 28 '18 at 22:13









George PantazesGeorge Pantazes

487618




487618








  • 1





    If the notification setting is saved in some browser profile, just use the profile in selenium. System.setProperty("webdriver.chrome.driver", chromedriver_path); ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=" + "C:\Users\pburgr\AppData\Local\Google\Chrome\User Data"); driver = new ChromeDriver(options);

    – pburgr
    Nov 30 '18 at 11:01
















  • 1





    If the notification setting is saved in some browser profile, just use the profile in selenium. System.setProperty("webdriver.chrome.driver", chromedriver_path); ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=" + "C:\Users\pburgr\AppData\Local\Google\Chrome\User Data"); driver = new ChromeDriver(options);

    – pburgr
    Nov 30 '18 at 11:01










1




1





If the notification setting is saved in some browser profile, just use the profile in selenium. System.setProperty("webdriver.chrome.driver", chromedriver_path); ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=" + "C:\Users\pburgr\AppData\Local\Google\Chrome\User Data"); driver = new ChromeDriver(options);

– pburgr
Nov 30 '18 at 11:01







If the notification setting is saved in some browser profile, just use the profile in selenium. System.setProperty("webdriver.chrome.driver", chromedriver_path); ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=" + "C:\Users\pburgr\AppData\Local\Google\Chrome\User Data"); driver = new ChromeDriver(options);

– pburgr
Nov 30 '18 at 11:01














0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528910%2fhow-to-programmatically-disable-cloud-print-new-printer-on-your-network-popup%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528910%2fhow-to-programmatically-disable-cloud-print-new-printer-on-your-network-popup%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks