Authentication Popup using Selenium Webdriver Python
<p>I'm able to send keys to handle the authentication popup of a site using Selenium and win32com.client. It is working fine when I run the code manually (running a Jupyter Notebook).</p>

<p>The error occurs when I convert .ipynb to .py and schedule it to run automatically using Windows Task Scheduler. It get stuck into the authentication popup window.</p>

<p>I have tried the options below:</p>

<p>1.) This works fine in notebook</p>

<pre><code>shell = comclt.Dispatch("WScript.Shell")
driver = webdriver.Chrome(chrome_path)
driver.maximize_window()
driver.get(url)
shell.SendKeys("username", + "{TAB}" + "password" + "{TAB}" + "{ENTER}")
</code></pre>

<p>2.) Just trying some alternatives and its working in notebook  </p>

<pre><code>shell = comclt.Dispatch("WScript.Shell")
driver = webdriver.Chrome(chrome_path)
driver.maximize_window()
driver.get(url)

try:
    alert = driver.switch_to_alert().accept()
    shell.SendKeys("username", + "{TAB}" + "password" + "{TAB}" + "{ENTER}")

except NoAlertPresentException:
    shell.SendKeys("username", + "{TAB}" + "password" + "{TAB}" + "{ENTER}")
</code></pre>

<p>Is there a better approach on how to run this code (.py) automatically using Task Scheduler? </p>

<p>Works well with .ipynb and py while in active desktop session
updates: 
added codes to minimize the Console Window Class</p>

<pre><code>app = Application().Connect(title ='path' + 'python.exe', class_name = 'ConsoleWindowClass')
cwc = app.ConsoleWindowClass
cwc.Minimize()

app = Application().Connect(title ='page', class_name = 'Chrome_WidgetWin_1')
widget = app.Chrome_WidgetWin_1
widget.Minimize()
time.sleep(2) # will allow the some time before executing other task
widget.Maximize()
widget.SetFocus()
time.sleep(3)
shell.SendKeys("username", + "{TAB}" + "password" + "{TAB}" + "{ENTER}")
</code></pre>

<p>It won't work when the computer is locked. Work around is to send a pyautogui for mouse events.</p>

<p>Again, it might not be the best solution but this is my temporary solution until your best approach :)</p>

python selenium-webdriver scheduled-tasks win32com pywinauto