Changing Chrome's settings with Selenium - google-chrome

I'm working on Chrome with Selenium and I'm looking to change a few settings within Chrome using the webdriver. Using Google and this site, I was able to get most of the settings working. However, a few more seem to escape me and hopefully I can get the answers here. I'm looking to alter the settings before launching the browser, such as using ChromeOptions, rather than using automation to navigate the settings page.
The settings I'm looking to change are as follows:
Disable Javascript
Disable the microphone
Change the home page
Altering the default search engine in the Omnibox
These 4 are giving me the most issues. Any help?

Perhaps this List of Chromium Command Line Switches will help. E.g.
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability("chrome.switches", Arrays.asList("--disable-javascript"));
And
Map<String, Object> preferences = Maps.newHashMap();
preferences.put( "browser.startup.homepage", "http://my.home.page" );
preferences.put( "browser.startup.page", START_WITH_HOME_PAGE );
capabilities.setCapability( ChromeOptions.CAPABILITY, preferences );
ChromeDriver driver = new ChromeDriver( capabilities );
Update
My guess is that the following
"import_search_engine": true
from Configuring other parameters will cause Chrome to ask you to select a search engine when it opens.
Turning off JavaScript makes chrome pretty much a no-op; I do not think that the option is supported. As far as microphones, that is more a system option. A search of about:config for microphone came up empty.

Related

How to disable “always open these types of links in the associated app” using a registry key

I have created a custom registry to launch few Urls in IE browser from Chrome.I have used below code.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"=""
#="URL:IE Protocol"
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
#="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
But i am getting a warning window as "always open these types of links in the associated app" before launching IE from chrome.
I am looking for the way to disable this warning window using chrome registry protocol handlers.
The below solutions is for selenium. But am looking similar kind of solution using Registry settings
How to disable "always open these types of links in the associated app" Chrome alert
Any help would be appreciated.
Thanks
I know you wanted a solution using registry keys to make "always open these types of links in the associated app" to disappear but I am providing a solution using Chrome preferences file.
Following line needs to be added in the Chrome Preferences file to disable the popup completely without being displayed when a link or exe is being launched.
"protocol_handler":{"excluded_schemes":{"XYZ":false}}
Note: XYZ is a protocol name of your app (through which the link is being opened), which you can get it from "HKEY_CLASSES_ROOT" in registry editor

Chrome extension to enable flash plugin

I am working for a game which runs in Adobe Flash. From Chrome 69, sites using Flash will require explicit permission to run it, every time the user restarts the browser. We are expecting lot of our players will get dropped off as they need to go through click-to-play flow every time they restart the browser.(Flash Roadmap -> https://www.chromium.org/flash-roadmap)
So we came up with an idea of using chrome extension which can enable flash plugin in background for our game website. We used 'chrome.contentSettings' for creating this extension.
Can someone please confirm if there is any roadmap plan from chrome to stop controlling of 'adobe-flash-player' plugin from 'chrome.contentSettings'.
Other words pls tell me how long below api code will work ?
var flashResIdentifier;
chrome.contentSettings.plugins.getResourceIdentifiers(function(resIdentifiers) {
for (var i=0; ihttps://abc.xyz.com/', 'resourceIdentifier':flashResIdentifier, 'setting':'allow'});
This will re-enable Flash manual white-listing
in the latest Chrome 69+ and higher
chrome://flags/#enable-ephemeral-flash-permission
Set to DISABLED
then use Flash manual white-listing by going here:
chrome://settings/content/flash
Then manually add all website URL links
that you need like before
in Chrome 68 and lower
After Chrome 71, you can persistently reenable flash for specific websites on Windows via a registry setting. Go to or create HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\PluginsAllowedForUrls, and add string values starting with a name of "1" and a value of the URL you wish to enable flash for (so, HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\PluginsAllowedForUrls\1 = "http://myawesomesite.com/*" to enable Flash for everything under myawesomesite.com).
There is a similar setting for OSX and Android. See here for more information.
I had the same problem in version 72 of Chrome, and the solution I found is the following:
Click the paddlock icon, and go to Site settings:
Then, on Flash option, select Allow
Refresh page, and that's all! :)
Reference: https://www.lifewire.com/enable-flash-in-chrome-4160696

pywinauto: accessing chrome gui

I am trying to select a printer and print on chrome browser, using pywinauto, but I am not able to access the gui components. I can see the components in Microsoft Inspect.exe in UIAutomation mode. (See screenshot).
I have started chrome with --force-renderer-accessibility flag.
I tried several things but I am not able to access anything in the chrome window. Is it possible to access the chrome gui components using pywinauto?
screenshot: ]1
Probably you use default backend="win32" which is used when you call Application(). To use MS UI Automation you have to set backend="uia" when instantiating Application object:
app = Application(backend='uia').start('chrome.exe <other params>')
My student wrote example script dragging file from explorer.exe to Google Drive in Chrome. Is it working for you?
P.S. If you already use backend='uia', please provide more detailed description with some code and output.

What is the difference between manually opened Chrome browser and opened using chrome driver

I am using Selenium for automating the chrome browser. When I download the files using automated Chrome browser it gives me a warning,
'This type of file can harm your computer' with keep or discard options.
But when I manually open chrome and download the files from same site, I won’t get any warnings.
I know I can disable the warnings using, options.AddUserProfilePreference("safebrowsing.enabled", true);
But my question is why I am getting this warning only in automated window?
What is the difference between browser opened using Chrome driver and manually opened browser?
Please help me.
If during your manual download, in your chrome
Settings > Advance Settings
Privacy -> Protect you and your device from dangerous sites (is_checked)
The download warning wouldn't be displayed on your browser.
On the other hand, not all chrome options are set to the same value during automatic download from your code. Hence you need to specify :
options.AddUserProfilePreference("safebrowsing.enabled", true);
List of all command line arguments for chrome driver goes here.
Note : Though not all of them are certainly of use while using automation and not all of them correspond to a chrome manual setting either.

Start Chrome emulation from command line

I use Google Chrome with Intern to run automated tests and I would like to know if there is a way to launch Chrome in emulation mode from CLI or using a specific flag to test mobile rendering. If not, do you know a good workaround ?
I could directly use the Android Emulator (from Android SDK) with Selenium Webdriver apk or with mobile Chrome but tests are crashing most of the time, emulators don't respond and I have to restart it. Also, I need to test on the largest possible scope, not limited to Android devices.
Chrome on desktop is a lot more stable and even if a test fails, chrome always respond and can be closed automatically by Intern.
I tried a workaround with the "--enable-touch-events" flag and with a custom userAgent but it's producing weird behaviors. Maybe some other flags would help me ?
Thank you in advance for your answer.
This is currently not possible in Chrome.
It's a feature I've been wanting myself too so I've gone ahead and filed a feature request for it at the following link:
https://code.google.com/p/chromium/issues/detail?id=373169&thanks=373169&ts=1400050662
I'm crossing my fingers but it wouldn't hurt if you and other people interested in this went and left a comment on the thread too. The more people asking for it, the higher the chance of it being implemented. And it does seem like it would be trivial to implement since it currently only takes a couple of mouse clicks to enter emulation mode.
Selenium allows users to emulate Chrome on a mobile device using code like this:
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Nexus 5");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
WebDriver driver = new ChromeDriver(chromeOptions);