0

I am trying to set a new download folder for my downloads with Selenium, but I am getting an error.

I am using:

options.add_argument('download.default_directory = C:\Users\User\Documents\folder') 

The error I get

File "C:/Users/GuilhermeMachado/PycharmProjects/untitled/Extranet_BTG.py", line 29
options.add_argument('download.default_directory = C:\Users\User\Documents\folder')
                    ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 31-32: truncated \UXXXXXXXX escape

What is wrong with it?

Guy
  • 46,488
  • 10
  • 44
  • 88
guialmachado
  • 506
  • 5
  • 17
  • @Guy there is no point in adding multiple python related tags e.g. [tag:python], [tag:python-3.x], [tag:python-2.7], etc to a single question. It doesn't adds any value. – undetected Selenium Mar 04 '20 at 13:21
  • @DebanjanB so remove `python-3` if you remove something, it's a version specific, not language specific. – Guy Mar 04 '20 at 13:23
  • @Guy The first edit was yours. With already 2,090 edits in your kitty it is expected that you would remove [tag:python-3] and add back [tag:python] or may be leave it as it is. – undetected Selenium Mar 04 '20 at 17:09

1 Answers1

1

You need to send it as a dict to add_experimental_option, and you need escape the path

options.add_experimental_option('prefs', {'download.default_directory': r'C:\Users\User\Documents\folder'})
Guy
  • 46,488
  • 10
  • 44
  • 88