I have written an script in python to navigate to a directory... right click on an specific file.. and then select an option from the context menu.. I have done this using pywinauto library. The code however is not fulfilling the purpose. It just takes me to the directory but does not do right click on the desired file. Could anyone give some input on this? This is my code.
# rightclick on the file and run the ps script
import time
import webbrowser
from pywinauto import Desktop, mouse
from pywinauto.application import Application
filepath = r"C:\BoschTools&Driver\i3_FlashAuto_latest"
script_name = "RestartEthernetAdapter.ps1"
option_to_select = "Mit PowerShell ausführen"
webbrowser.open(filepath)
# get the filename
abs_script_path = os.path.join(filepath, script_name)
try:
desktop = Desktop(backend='win32')
file_element = desktop.window(title=script_name)
time.sleep(3)
file_element.click_input(button='right')
time.sleep(1)
context_menu = desktop.window(class_name='ContextMenu')
context_menu.child_window(title=option_to_select).click_input()
except Exception as e:
print(f"Error {e} occured")