0

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.

user2334659
  • 27
  • 1
  • 8
  • Is there a reason you cannot import the second file and directly call the function you want? If command line call is your only way forward for some reason, use the `subprocess` module to do this. See this other answer: https://stackoverflow.com/questions/89228/how-do-i-execute-a-program-or-call-a-system-command – blarg Jul 13 '22 at 09:22
  • You can add arguments to the command: `...sec_handler.py username password` you just need to read them using `argparse` or `sys.argv` – Maurice Meyer Jul 13 '22 at 09:25
  • @blarg The use of os.system appears to be the only workaround for the fact that autoit and selenium won't play nicely together with multi-threading. Using import or subporcess leads to sec_handler.py just running in a never ending loop. – user2334659 Jul 13 '22 at 09:55
  • @MauriceMeyer I'm a bit stuck on the syntax. os.system("C:/Users/val/Documents/code/rmscheck/sec_handler.py" username password) gives me a syntax error (sorry I can't seem to put code snippets in this section. – user2334659 Jul 13 '22 at 09:59
  • See this other question: https://stackoverflow.com/questions/22101931/passing-more-than-one-variables-to-os-system-in-python – blarg Jul 13 '22 at 10:03

0 Answers0