0
  1. Unable to upload file even using autoit as my IE browser taking long to open upload popup once we click on the browse button but my script runs when i execute manually.

  2. Also my objective is, i need to export a file and next step is to upload the latest timestamp file from the exported files. Can we handle these kind of scenario using AutoIT or if any please suggest.

  3. One more step is to open and edit the exported excel file and import the same file.

Please suggest me with ur thoughts on it.

Script used for upload:

WinWaitActive("Choose File to Upload","",10)
Sleep(1000)
ControlFocus("Choose File to Upload","","Edit1") ; FILE UPLOAD
Sleep(2000)
ControlSetText("Choose File to Upload","","Edit1",""C:\Desktop")
Sleep(2000)
ControlClick("Choose File to Upload","","Button1") ; CLICK ON OPEN BUTTON
Sleep(1000)
1

Depending on what you are testing (i.e. the actual process of using the upload control, or just the ability to upload / validate a file) you can skip the upload popup entirely. This also means you don't need autoit (which will mean you can run the tests on unattended (locked) machines.

e.g. Generally any upload button will be something like the below when viewed in the DOM:

<input type="file", id="File", name="import", accept=".csv">

You can just manipulate that directly (example in java):

By fileUpload = By.id("File");

public void uploadFile(String filePath) {
    wait.until(ExpectedConditions.visibilityOfElementLocated(fileUpload));
    wait.until(ExpectedConditions.elementToBeClickable(fileUpload))
    driver.findElement(fileUpload).sendKeys(filePath);

    }

Then just click your upload / save / etc button.

Alternatively add some explicit waits (wait until condition met, as per above) to wait for things rather than implicit (always waiting a set amount of time).

0

For actions on a component or page that can take some time to load, using sleep isn't very optimal or recommended.

If you're able to look for and find a webelement related to this popup, you can wait for that webelement to be clickable, present, visible, ...
Using this you can set a maximum time duration for the wait but once the element is found and checked against whatever state you define it should be in, the check will pass and the execution can move on to a next step.

An example of code with a max waiting time of 5 sec could be:

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.cssSelector("whatever is needed to find this element"))));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.