0

I am trying to autonomously download some CSVs on a regular basis from a website at my organization. They were so kind as to not afford me back-end database access or an API so I am having to hobble together something to take care of this for me. The website is an Oracle PeopleSoft site that prompts with a Windows Security modal before the page even loads.

I am using Edge because the site doesn't seem to like Firefox and Chrome is giving me trouble in Selenium. I have in the past been able to scrape from OBIEE sites in this manner but this one is giving me trouble. The code below is what I am using to access the page and attempt to handle the login modal. Stepping through my code it seems that I don't get past the driver.get(url) line at all.

Does anyone have suggestions on how to handle this?

enter image description here

driver = webdriver.Edge(EdgeDriverManager().install())
driver.get(url)
# Wait till the modal prompts you to log in
wait(driver, 5).until(EC.alert_is_present())
alert = driver.switch_to_alert()
# Provide creds with a tab in between so that you change from username field to password field
alert.send_keys(config.myUSERNAME + Keys.TAB + config.myPASSWORD)
# click ok
alert.accept()

EDIT: 01/25/2018

Trying to use Autoit as suggested and I am still having problems. The webdriver seems to not allow anything else to happen while its running. Any suggestions on how to handle this?

def browser(url):
    driver = webdriver.Edge(EdgeDriverManager().install())
    driver.get(url)


def login_handler(username, password):
    print('This print never gets run? What is up with this?!')
#     autoit.win_wait_active("Credential Dialog Xaml Host")
    autoit.win_exists("Windows Security", "CORP\\")
#     also tried this
#     autoit.win_wait_active("Windows Security")
    autoit.send(username)
    autoit.send("{TAB}")
    autoit.send(password)
    autoit.send("{ENTER}")

t1 = Thread(target=browser(url))
t2 = Thread(target=login_handler(config.myUSERNAME, config.myPASSWORD))
t2.start()
t1.start()
Matt Camp
  • 1,448
  • 3
  • 17
  • 38
  • 1
    Windows dialog boxes are not automated by Selenium. You can try something like autoit or robot framework. – demouser123 Jan 12 '18 at 19:33
  • I'm trying to use Autoit to handle this but I can't figure out how to get Python to let me do multi-threading with the webdriver. I have tried to use Thread() but it keeps hanging on the driver.get() call even though its suppose to be in a separate thread from my Autoit code. – Matt Camp Jan 25 '18 at 20:48

1 Answers1

0

It appears that its not possible to multi-thread Selenium and Autoit, or at least I haven't figured it out yet (feel free to prove me wrong..please). I was able to side step this problem by just running the autoit script from the selenium script.

windows_securit_login_handler.py

import autoit
import os
import config
import datetime
import time

def login_handler(username, password):
    """
     Hey Windows Security People this is what I think of you pesky Windows Security modal (ಠ_ಠ)┌∩┐
     Python to rule the world!
    :param username: String
    :param password: String
    :return:
    """
    # just chill out and wait to see a window with the title 'Windows Security
    autoit.win_wait("Windows Security")
    # now make that crap active so we can do stuff to it
    autoit.win_activate("Windows Security")
    # type in the username
    autoit.send(username)
    # tab to the password field
    autoit.send("{TAB}")
    # type in the password
    autoit.send(password)
    # kill!
    autoit.send("{ENTER}")

if __name__ == "__main__":
    # cause this is not thread safe or I am too ignorant to figure out how to do this in single python program
    # I am running this in the background persistently so that the scraper doens't ever have to worry about the 
    # silly Windows Security modal

    while True:

        try:
            login_handler(config.myUSERNAME, config.myPASSWORD)
        except:
             print("Got some ERROR @ {} \nAnd I'm too laszy to figure out how to deal with it properly so you get this message.".format(datetime.datetime.now()))

scraper.py

from webdriver_manager.driver import EdgeDriver
from webdriver_manager.microsoft import EdgeDriverManager
from selenium import webdriver
import sys
import os

os.system('python windows_securit_login_handler.py')
driver = webdriver.Edge(EdgeDriverManager().install())
driver.get(url)
... more code to do scraping type things ... 
Matt Camp
  • 1,448
  • 3
  • 17
  • 38