0

Python script with Selenium browser flow.

Windows Server 2016 Standard Python 3.8.1 Firefox 86.0

Executing the python script (always non-healess i.e. with option headless DISABLED) from Windows in 3 different ways:

a) manually from cmd window prompt "python scriptname.py" b) from Task Scheduler with option "Run only when user is logged on" c) from Task Scheduler with option "Run whether user is logged on or not"

Always logged in as Administrator and Task Schedule entry for the script setup as "When running the task use the following account: Administrator". User Administrator has Desktop Enabled.

Need to take screenshots at different steps of the python script above for two scenarios:

  1. show what is seen in the browser context (using browser.save_screenshot works fine)
  2. show a complete screen dump that includes the whole screen including the browser.

The challenge is in step 2) above.

To create pics with complete screen dump of the whole screen I have tried: pyautogui.screenshot() PIL wx Pillow mss

All of the above work fine when running the script by hand or from Task Scheduler in mode "Run only when user is logged on"

They fail when running from Task Scheduler in mode "Run whether user is logged on or not"

The only screen dump option that has worked in all modes, manually, TS in mode "Run only when user is logged on" and TS in mode "Run whether user is logged on or not" is:

image = pyscreenshot.grab() image.save("GeeksforGeeks.png")

It produces a fine screendump when Task Scheduler is in mode "Run only when user is logged on" HOWEVER when executing from Task Scheduler in mode "Run whether user is logged on or not" IT PRODUCES A TOTALLY BLACK PIC.

Summary:

I) Running script by hand a pic of the browser context and a pic of the complete screen is correctly created and saved to disk.

II) Running from Task Scheduler "Run only when user is logged on" a pic of the browser context and a pic of the complete screen is correctly created and saved to disk.

III) Running from Task Scheduler "Run whether user is logged on or not" a pic of browser context is correctly created and saved to disk. However all apps (pyautogui.screenshot(), PIL, wx, Pillow, mss) give an error

Someone have an idea of what is the problem?

  • Related: https://superuser.com/questions/1528074/windows-10-task-scheduler-wont-run-any-exe-if-set-to-run-whether-user-is-logge Essentially you are running as a sandboxed and isolated user in that particular mode, one that may have it's own "desktop" interface or none at all. – Mokubai Feb 28 '21 at 18:13
  • Thanks. Actually running the script as "Run only when user is logged on" in an attended execution (not minimizing the Remote Connection window) it runs just fine and the Desktop is there. However if I start the job and detach (no logout or close the session, just detach with the cross on upper right corner) the script fails since the desktop is gone. Don't understand how it 'disappears' ore becomes deactivated. Any ideas? – Claudinho Mar 01 '21 at 13:00

0 Answers0