1

I've read and tested many solutions but none of them worked. I'm automating tweeter post: I write my tweet, works fine, and then, I click on the Add Pic button ; the windows open file dialog box pops up. I want to change the directory. Here's my actual code:

options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\Users\\Jake\\AppData\\Local\\Google\\Chrome\\User Data\\Default") 
prefs = {"download.default_directory" : "E:\\Images\\tweeter\\","directory_upgrade": True,"extensions_to_open": ""}
options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(executable_path='C:\\Program Files (x86)\\chromedriver.exe', chrome_options=options)

Doesn't work.

Other solution found elsewhere:

options.add_argument("download.default_directory=E:\\Images\\tweeter\\")

Doesn't work.

Other one:

prefs = {"profile.default_content_settings.popups": 0,
             "download.default_directory": 
                        r"E:\Images\tweeter\\",#IMPORTANT - ENDING SLASH V IMPORTANT
             "directory_upgrade": True}
options.add_experimental_option("prefs", prefs)

Doesn't work.

Any idea?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
jackgames
  • 71
  • 9

1 Answers1

0

My suggestions?

Copy and paste the geckodriver (selenium drive for chrome) in the same place where Chrome is installed (not the shortcut place). Then try to run it manually as br = webdriver.Chrome() with no params. It should work fine.

Deshwal
  • 3,436
  • 4
  • 35
  • 94
  • If I run it with no params, how tot tell the driver which directory I want? The point is that I have to change the directory several times and I'd like these changes to be totally automated... – jackgames Jul 14 '20 at 08:45
  • Have you tried it? Try doing it. You can code in any directory as long as Chrome.exe and gecodriver.exe are in same place – Deshwal Jul 14 '20 at 09:09
  • Sorry but I can't follow your thoughts: I've done what you said. Copied chromedriver.exe (I think you meant this cause geckodriver=Firefox) to google chrome application directory and now my code is: `driver = webdriver.Chrome(executable_path='C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe')`. And now? How to tell chromedriver the directory I want? When I click the Add Pic button of Tweeter, windows explorer opens up in: my user's directory... – jackgames Jul 14 '20 at 10:06
  • P.S: I launched chromedriver as you said: `driver = webdriver.Chrome() – jackgames Jul 14 '20 at 10:35
  • I just noticed something: I launched my python script as it was in the 1st version (see my 1st msg). Then, keeping the chromedriver open, I went in menu parameters, looked at default downloads location, and , surprise: it has been well changed to `E:\\Images\\tweeter\\` as I wrote in the chromedriver options. I thought the download folder and the **openfile dialog** folder were the same, but this means it's not! So how to change the openfile dialog directory that opens when you want to **upload** an image? – jackgames Jul 14 '20 at 11:36
  • As far as I've read until now, this parameter is handled by Windows... It should be saved in the Registry but I can't find where and how. If it's not possible to change it with Python, I think the only way is to automate it with Pyautogui when select file dialog box pops up. – jackgames Jul 15 '20 at 04:06