I created an executable in Python but it doesn't always start properly at startup

30 Views Asked by At

To explain, I work in a production environment and we use TVs with TV sticks to display information through a web based application called ShopLogix.

One of our duties is to go around in the morning and ensure that all TVs are up and operational. I attempted to write a script that would automate this process anytime the PC was rebooted. The script will open Chrome, input the URL, log in with credentials, and then full screen the web browser.

If I double click the .exe it works fine, however, when I add it to the startup folder it will do 1 of 2 things. It will open chrome in a small window and just diplay data: in the URL box or it will start ShopLogix but won't full screen.

I will attach screenshots of the data: issue as this is the most common and will post my code (excluding the URL and username/password).:data issue

Here is the code

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time

options = Options()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
time.sleep(2)
driver = webdriver.Chrome(options=options)
time.sleep(2)
driver.maximize_window()
time.sleep(2)
driver.get("URL GOES HERE")
username = driver.find_element(By.NAME, "Username")
username.send_keys("USERNAME GOES HERE")
driver.find_element(By.NAME, "button").click()
password = driver.find_element(By.NAME, "Password")
password.send_keys("PASSWORD GOES HERE")
driver.find_element(By.NAME, "button").click()
time.sleep(2)
driver.fullscreen_window()
while True:
    pass

To add a little more detail, I at first did not have any time.sleep but added those hoping it would rectify the issue. I also tried to put the .exe file into the temp folder, and a batch file in the startup that had a 30 second timer and would then launch the .exe thinking that perhaps the issue was not giving Windows time to load and a wifi connection to be established. Issue still persist.

This is explained in the details of the post.

1

There are 1 best solutions below

0
Luke Carter On

Since the program runs fine manually it's probably an issue with the Windows startup rather than the python or selenium installation and commands. I would try some of the solutions suggested in this thread: How to start a python file while Windows starts?