Home > Mobile >  not able to upload image in selenium
not able to upload image in selenium

Time:10-06

i am using selenium and i want to upload a pic in my project directory

<div _ngcontent-c2="" class="filesborder filesborder-single"><form _ngcontent-c2="" novalidate="" class="ng-untouched ng-pristine ng-valid"><input _ngcontent-c2="" class="inputfile inputfile-4" data-multiple-caption="{count} files selected" id="file-5" name="file-5[]" style="opacity: 0;" type="file" accept=".png,.jpg"></form><label _ngcontent-c2="" for="file-5"><div _ngcontent-c2="" class="col-12 mt-2"><h5 _ngcontent-c2="" class="font-weight-bold pt-2 mb-0">Upload Signature</h5><div _ngcontent-c2="" class="info-txt small"> ( Accepted: .JPG and .png, 20 MB)</div></div><div _ngcontent-c2="" class="col-12 d-flex justify-content-left align-items-center mt-2"><div _ngcontent-c2="" class="btn-bordered-browse">browse </div></div></label></div>

i am using sends key method..

String filepath = System.getProperty("user.dir")   "\\FileToUpload\\download.png";
File file = new File(filepath);
    String path = file.getAbsolutePath();
    utils.ExplicitWaiting.explicitWaitVisibilityOfElement(browsesign, 120);
    browsesign.sendKeys(path);


@FindBy(xpath="//div//form//input[@id='file-5']")
private WebElement browsesign;

i get this exception error-:org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of [[ChromeDriver: chrome on XP (603e78d403504acd56011da02e09a314)] -> xpath: //div//form//input[@id='file-5']] (tried for 120 second(s) with 500 milliseconds interval)

help me. Thanks in advance

CodePudding user response:

It Seems there is some issue in xPath which you have created.why are you using //div//form//input[@id='file-5'], you can simply use //input[@id='file-5']

CodePudding user response:

Selenium will not do file upload and download functionalities, those actions are interacting via desktop application. selenium can only do operations which is completely rely on browser. you can only click the the buttons such as upload file, download files. please use sikuli to select files from local storage.

<!-- https://mvnrepository.com/artifact/org.sikuli/sikuli-api -->

<dependency>
   <groupId>org.sikuli</groupId>
    <artifactId>sikuli-api</artifactId>
    <version>1.2.0</version>
</dependency>

in your case you can only click the button, you xpath is

//input[@type='file']
  • Related