0

I tried uploading file to selenium using javascriptexecuter but it throwed an error like "This is insecure"

this is the tag i worked upon

{input type="file" name="fileUploader" id="fileUploader-fu" tabindex="-1" size="1"}

{input type="hidden" name="charset"}

{input type="hidden" id="fileUploader-fu_data" name="fileUploader-data" value=""}

and i used

try {

        WebElement elem=driver.findElement(By.xpath("//input[@name='fileUploader']"));
        driver.
        ((JavascriptExecutor)driver).executeScript("arguments[0].value = arguments[1];", elem, "./payloads/SalesOrderSummary.xsd");
    System.out.println("here2");
    }
    catch(Exception e)
    {
        System.out.println(e);
    }

it gave me error like This is insecure

are there any alternatives to upload or any solution.

Thanks

Prince Singh
  • 1
  • 1
  • 4

1 Answers1

0

Yes you can upload the files using sendkeys too sendkeys is not only send string to textboxs while it sets the value in your DOM too

So try this out

driver.findElement(By.xpath("//input[@name='fileUploader']")).sendKeys(GIVE ABSOLUE PATH OF YOUR FILE);

Click on upload button too after this :)

get back to me if still facing problem :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125