The Chrome settings that drive this functionality can be viewed using the chrome://settings/. These settings are stored in the Chrome Profile. The path to this profile can be found using chrome://version/. In the preferences
file a JSON structure of settings can be found.
In the below Robot Framework example the script opens Google and then clicks on the microphone icon to start the voice search. Under normal circumstances this results in a pop-up for microphone access.
The reason the assignment is split into two variables is because the url contains characters (. : //
) that are considered separators. This is then overcome by creating that part of the structure manually: Create Dictionary https://www.google.nl:443,*=${SiteOptions}
.
This then results in the desireable preference structure:
...
"profile":{
...
"content_settings": {
...
"exceptions": {
...
"media_stream_mic":{
"https://www.google.nl:443,*":{
"last_used":1492245954.955647,
"setting":1
}
},
Robot Script:
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Chrome With Preferences
${chrome_options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
&{SiteOptions} Create Dictionary last_used=${1470931206} setting=${1}
&{media_stream_mic} Create Dictionary https://www.google.nl:443,*=${SiteOptions}
${prefs} Create Dictionary profile.content_settings.exceptions.media_stream_mic=${media_stream_mic}
Call Method ${chrome_options} add_experimental_option prefs ${prefs}
Create WebDriver Chrome chrome_options=${chrome_options}
Go To https://google.com
Click Link css=#gs_st0 > a # Click the search microphone icon.
sleep 5s
[Teardown] Close Browser