Reputation: 769
I am trying to download a file from a link on webpage. However I get annoying warning "This type of file can harm...anyway? Keep, Discard". I tried several options to avoid the warning but still getting it. I am using robot framework however I am using python to create new keyword for me.
@keyword('open "${url}" in chrome browser')
def open_chrome_browser(self, url):
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_argument("--disable-web-security")
options.add_argument("--allow-running-insecure-content")
options.add_argument("--safebrowsing-disable-extension-blacklist")
options.add_argument("--safebrowsing-disable-download-protection")
prefs = {'safebrowsing.enabled': 'true'}
options.add_experimental_option("prefs", prefs)
self.open_browser(url, 'chrome',alias=None, remote_url=False, desired_capabilities=options.to_capabilities(), ff_profile_dir=None)
Can someone please suggest a way to disable the download warning?
Upvotes: 1
Views: 25154
Reputation: 1
For me worked code below:
UI Test Case in Chrome
${chrome_options} = Evaluate selenium.webdriver.ChromeOptions()
Call Method ${chrome_options} add_argument --start-maximized
Call Method ${chrome_options} add_argument --window-size\=1420,1080
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --no-sandbox
Call Method ${chrome_options} add_argument --disable-dev-shm-usage
Create WebDriver Chrome options=${chrome_options}
Set Selenium Implicit Wait 15s
Upvotes: 0
Reputation: 31
The below would be a simpler solution:
Open Browser ${URL} ${BROWSER} options=add_argument("--disable-notifications")
for multiple option, you can use with ; seperated.
options=add_argument("--disable-popup-blocking"); add_argument("--ignore-certificate-errors")
Upvotes: 3
Reputation: 85
This worked for me (must use SeleniumLibrary 4
). Modify Chrome so it downloads PDFs instead of viewing them:
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${disabled} Create List Chrome PDF Viewer PrintFileServer
${prefs} Create Dictionary download.prompt_for_download=${FALSE} plugins.always_open_pdf_externally=${TRUE} plugins.plugins_disabled=${disabled}
Call Method ${chrome_options} add_experimental_option prefs ${prefs}
${desired_caps}= Create Dictionary browserName=${browserName} version=${version} platform=${platform} screenResolution=${screenResolution} record_video=${record_video} record_network=${record_network} build=${buildNum} name=${globalTestName}
Open Browser url=${LOGINURL} remote_url=${remote_url} options=${chrome_options} desired_capabilities=${desired_caps}
Upvotes: 0
Reputation: 1565
It is better not to disable any security features or any other defaults(unless there is ample justification) which comes with the browser "just to solve one problem", it would be better to find the solution by not touching it at all, and
just make use of requests modules in python and use the same as keyword, wherever you would want later on in all of your codebases. The reason for this approach is that it is better to get the job done making use of ubiquitous modules rather than spending time on one module for extensive amounts of time, I use to do that before, better install requests + robotframework-requests library and others to just get the job completed.
Just use the below code to create a keyword out of it and call it wherever you want, instead of going through the hassle of fixing browser behavior.
import requests
file_url = "http://www.africau.edu/images/default/sample.pdf"
r = requests.get(file_url, stream=True)
with open("sample.pdf", "wb") as pdf:
for chunk in r.iter_content(chunk_size=1024):
# writing one chunk at a time to pdf file
if chunk:
pdf.write(chunk)
Upvotes: 0
Reputation: 1508
You need to add all the params in list. Then pass this list to Dictionary object and pass it to open browser. Ex.
${list} = Create List --start-maximized --disable-web-security
${args} = Create Dictionary args=${list}
${desired caps} = Create Dictionary platform=${OS} chromeOptions=${args}
Open Browser https://www.google.com remote_url=${grid_url} browser=${BROWSER} desired_capabilities=${desired caps}
Upvotes: 5
Reputation: 769
I found an answer with some research. For some reason (may be a bug) open_browser does not set capabilities for chrome. So, the alternative is to use 'create_webdriver'. Worked with following code:
@keyword('open "${url}" in chrome browser')
def open_chrome_browser(self, url):
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_argument("--disable-web-security")
options.add_argument("--allow-running-insecure-content")
options.add_argument("--safebrowsing-disable-extension-blacklist")
options.add_argument("--safebrowsing-disable-download-protection")
prefs = {'safebrowsing.enabled': 'true'}
options.add_experimental_option("prefs", prefs)
instance = self.create_webdriver('Chrome', desired_capabilities=options.to_capabilities())
self.go_to(url)
Upvotes: 4