简体   繁体   中英

Passing arguments to AutoIt program using Python

Here is the AutoIt code to upload a file every time when it gets executed in Python. I replaced the file path to $CmdLine 1 so that I can pass a new file path every time.

ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1", "$CmdLine[1]")
ControlClick("Open","","Button1")

How can I pass a new file path using Python? I use

os.startfile('path to the autoit.exe file')

I read that there is a way to pass such argument in java as follows,

Runtime.getRuntime().exec(r"path to autoit.exe file"+""+"file path to be uploaded");

When I tried to execute this cmd using command line it doesn't pass the desired arguement.

AutoIt3.exe C:\Users\Downloads\file_upload.exe C:\Users\Downloads\1.png

在此处输入图像描述

It types the same $CmdLine 1 argument in the text field as follows. 在此处输入图像描述

Is there any other way that I can pass a new file name as an argument in python's for loop so that It will upload multiple files?

Here is the code for adding images to Google slides website.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import os
options = Options()
options.add_argument("start-maximized")
options.add_argument("user-data-dir=C:\\Users\\praba\\AppData\\Local\\Google\\Chrome\\User Data\\")
#options.add_argument("--profile-directory='Profile 1'")
driver = webdriver.Chrome(executable_path=r'chromedriver',options=options)
time.sleep(5)
driver.get("https://docs.google.com/presentation/u/0/create?usp=slides_web")
time.sleep(5)
elem = driver.find_element_by_id('insertImageMenuButton')
time.sleep(5)
elem.click()
time.sleep(5)
el1 = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH,'/html/body/div[35]/div[1]/div/span')))
el1.click()
time.sleep(3)
os.startfile(r"C:\Users\praba\Downloads\file_open.exe")

I found the solution after a lot of struggle. The problem was the double quotes on the $CmdLine[1] parameter.

ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1", $CmdLine[1])
ControlClick("Open","","Button1")

So removing the double-quotes and calling the exe file from the command line opens the desired file.

os.system('commandline to execute autoit program with the uploading file path')

Can you maybe add a little more context? How would you be retrieving the new file path? I will try to answer based on the information you've provided.

If it's in an automated fashion, you should in theory be able to just call that ControlSetText with the new path (string) you've retrieved.

If you need to input it manually, you can call something like input('Please enter the new file location. \n') and store that in a variable you then pass into the ControlSetText .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM