I am using the solution in Python Selenium Webpage with Windows Security to try and deal with the Windows Security prompt when I try and load up a web page. Using the solution in that post as a reference I have created the following:
script1.py - the program will basically load up a webpage and press a button on it
from selenium import webdriver
from pathlib import Path
import webbrowser
import time
import os
import autoit
#Login details
print("Enter username")
username = input()
print("Enter password")
password = input()
#Input from user for variables
print("Enter URL")
url = input()
print("How many pings do you want performed?")
no_of_pings = int(input())
print("How many minutes apart do you want the pings?")
delay = int(input())
html_file = Path.cwd() / "Documents/RequestSummary.html" #my sample page for local testing only
def ping():
os.system("C:/Users/val/Documents/code/rmscheck/sec_handler.py")
driver = webdriver.Firefox() #define which browser to use
driver.get(html_file.as_uri()) #load website from local file
time.sleep(10) #pause to allow page elements to load
button = driver.find_element_by_name("repingButton") #get reping button name
#button.click() #click the button
print(button) #for testing purposes only
print("Ping", x, "successful")
driver.close() #close web browser
for x in range(no_of_pings):
#login(username, password)
ping()
if x < no_of_pings:
time.sleep(delay * 60) #time delay
else:
break
print("Program complete") #termination message
sec_handler.py
import autoit
import os
import datetime
import time
user = "blah"
auth = "blah"
def login(username, password):
autoit.win_wait("Windows Security") #wait for window with title Windows Security
autoit.win_activate("Windows Security") #make window active
autoit.send(username) #complete username field
autoit.send({"TAB"}) #tab to next field
autoit.send(password) #complete password field
autoit.send({"ENTER"}) #send
def main(user, auth):
if __name__ == "__main__":
while True:
try:
login(user, auth)
except:
print("Error")
I want to be able to pass the username and password that the user input in script1.py to sec_handler.py but I'm not sure how to do this. os.system() apparently only takes one argument.