1
driver.wait(until.elementLocated(webdriver.By.css('div.border-right:nth-child(2)')), 1000)
.then((element) => {
element.click();
});

I am using java-script for my test cases. I had an issue to upload image, upto click the upload button i did. I don't know how to fetch the data from the system storage because input tag had a style as display:none. When I tried

sendKeys() --> elementNotInteractable error occurrs.

In this scenario how can I upload image using selenium webdriver in javascript without test framework?

  • Please edit your post and add the code of the page your are trying to automate. – Kate Paulk Jul 26 '18 at 11:32
0

Try using Robot class for image upload functionality.The following code works,

    driver.findElementByXPath("locate the file upload button']").click();
    Thread.sleep(10000);
    StringSelection stringSelection = new StringSelection("specify the path where your file is located");
   Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
   Robot robot = new Robot();
   Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
   robot.keyPress(KeyEvent.VK_CONTROL);
   robot.keyPress(KeyEvent.VK_V);
   robot.keyRelease(KeyEvent.VK_V);
   robot.keyRelease(KeyEvent.VK_CONTROL);
   Thread.sleep(5000);
   robot.keyPress(KeyEvent.VK_ENTER);
   robot.keyRelease(KeyEvent.VK_ENTER);
  • Thank you for your prompt reply. But i want in javascript for this case. – Priyadharshini Hariharan Jul 26 '18 at 11:16
0

Uploading files in selenium is done by using the sendKeys() method in case of the file-select button/field has 'input' tag. For instance:

WebElement uploadElement = driver.findElement(By.id("IdName"));
uploadElement.sendKeys("C:\filename.pdf")

Otherwise, you can use a Robot class or Autoit for same.

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.