While running through bamboo(CI), my script is getting failed where all "upload file link" is not starting with the input tag. I am using Auto IT for uploading the file which is working fine locally and when I am trying to run through Bamboo on remote machine it is getting failed there.

So want to upload file from back-end where i don't want to click upload button.

Sendkeys() tried but not helpful in this scenario.

Thnaks in advance

2

There are 2 answers

0
dmr On

Well, usually in this situation you need to do 3 steps:

  • make input[type=file] element visible use javascript for that
  • locate this input and use send_keys(PATH_TO_FILE_ON_YOUR_MACHINE)
  • use javascript to trigger upload
0
Maddy On

Why can't you try this.. is your webpage has browse button to locator file? if yes, pass the element to locatorUpload para and pass upload button element to locatorButton

public void UploadFile(By locatorUpload, By locatorButton, String filePath){

        driver.findElement(locatorUpload).sendKeys(filePath);
        waitForElementClickable(driver, locatorButton, 4);
        driver.findElement(locatorButton).click();

    }

public void waitForElementClickable(WebDriver driver, By locator, Integer timeoutInSeconds){
    WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
    wait.until(ExpectedConditions.elementToBeClickable(locator));
}