0

I am using the following code, but unable to find the file "test.html" on my local computer on the specified path. Also, the code does not give an error when I run it. Could someone please help me with locating my file?

pyautogui.hotkey('ctrl', 's')
time.sleep(2)
FILE_NAME = 'C:\\file_path_on_my_computer\\test.html'
pyautogui.typewrite(FILE_NAME)
pyautogui.hotkey('enter')
magarwal
  • 1
  • 1
  • Does "Save Dialog" open? Do you observe the program typing each letter? – Seljuk Gulcan Jul 25 '20 at 14:33
  • The "Save Dialog" does not open. I see that the page scrolls down to the bottom and that is where the code stops running. I feel that instead performing the action of "saving" the code is performing the action of "scrolling down". Any recommendations on how to open the save dialog? – magarwal Jul 25 '20 at 15:06
  • Note that there is no time delay before ctrl+s action in your code. If you are running the script from console or IDE, ctrl+s action can be already completed by the time you open the browser. Add a time delay before the first line and try again. – Seljuk Gulcan Jul 25 '20 at 15:17

1 Answers1

4

From this issue on GitHub I can see that this is not working for a lot people who uses a specific Operating System and Python version. You can use KeyDown, KeyUp and press instead.

pyautogui.keyDown('ctrl') # hold ctrl key
pyautogui.press('s') # press s key
pyautogui.keyUp('ctrl') # release ctrl key

time.sleep(2)
FILE_NAME = 'C:\\file_path_on_my_computer\\test.html'
pyautogui.typewrite(FILE_NAME)

The hotkey used to be passed several key strings which will be pressed down in order, and then released in reverse order. Don't use that to just press enter, use the press method instead

pyautogui.press('enter')
dsasd
  • 222
  • 1
  • 8
  • Thanks for the recommendation. I tried it but it did not open the save dialog.. Instead it scrolled down the webpage and that was it.. Any another recommendation? – magarwal Jul 25 '20 at 15:08
  • Note that this does work to save as complete web page. However it will act on whichever browser page is currently active. So if you run this code while moving between browser windows it may save the other pages. – curtisp Dec 17 '21 at 15:48