Jump to content

UDF Webdriver: Can NOT start Chrome with the option "ask where to download"

Recommended Posts

Hello there.

I want to download files from a web but giving them a reasonable name. I am using Chrome through DanP2's WebDriver UDF and chromedriver.exe.

The problem is that everytime Chrome starts, it does NOT remenber to ask where to download the files. I have tried loading an existing profile or setting the "DesiresCapabilities" option, but the "ask where to download" option is still off.  See the lines between long comment lines at the bottom of the code below.

#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <Array.au3>
#include "wd_core.au3"
#include "wd_helper.au3"

Local $RutaDescarga = "C:\TEMP\"
Local $URL = "https://someURL/"
Local $CSV = "CodeToDownloadSomething"
Local $sSession
Local $sDesiredCapabilities
Local $sElement

_WD_Timeouts($sSession, '{"pageLoad":20000}')

; Open Chrome and load URL
If @error <> $_WD_ERROR_Success Then
    Exit -1
$sSession = _WD_CreateSession($sDesiredCapabilities)
If @error = $_WD_ERROR_Success Then

; Fill in the code and click the download button
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='code']")
_WD_ElementAction($sSession, $sElement, 'value', $CSV)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='validate']")
_WD_ElementAction($sSession, $sElement, 'click')
_WD_LoadWait($sSession, 2000)

MsgBox($MB_SYSTEMMODAL, "Test Message", "Click to close browser")

Func SetupChrome()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
; **********************************************************************************************************
; Despite of the following line, Chrome does NOT ask where to download the file :-(
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true , "prefs": {"download.prompt_for_download": "True", "download.default_directory": "C:\\TEMP\\"}}}}}'

; Another NON working option is to load a profile (it also turns the "ask where to download" option off)
; $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\myAccount\\AppData\\Local\\Google\\Chrome\\User Data\\Default"], "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'
; **********************************************************************************************************

Func NavegarURL()
    _WD_Navigate($sSession, $URL)
    _WD_Attach($sSession, $URL, "URL")

Any help will be much welcome. Thanks in advance.



Link to post
Share on other sites

Have you tried it without the quotes around the word True? If that doesn't work, then try to break the prefs string down further. Something like this --

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true , "prefs": {"download":{"prompt_for_download": true, "default_directory": "C:\\TEMP\\"}}}}}}'


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...