0

I am writing a script in selenium using webdriver and nunit to automate my web application. I have to upload file in my application. But unable to do it.

The dialog opens while browse button is clicked, and upon selecting file the file is uploaded.

Browse

How can i do it in selenium?

Wesley Lomax
  • 2,067
  • 2
  • 20
  • 34
  • possible duplicate of [How to Upload files using Selenium webdriver in Java](http://stackoverflow.com/questions/16896685/how-to-upload-files-using-selenium-webdriver-in-java) – Würgspaß Sep 24 '15 at 12:41

2 Answers2

0
Answer is already available on stack, still I am repeating:

find the upload button, create webelement of this and follow this code:

   //open upload window
    upload.click();

    //put path to your image in a clipboard
    StringSelection ss = new StringSelection(<give file location>);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);

    //imitate mouse events like ENTER, CTRL+C, CTRL+V
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
Pankaj Kumar Katiyar
  • 1,474
  • 1
  • 20
  • 36
  • I am using C# with selenium. And i have tried this driver.FindElement(By.Id("pickfiles")).SendKeys("D:\\file1.rar"); But it is not working. I also tried using AutoIT but unable to run exe file provided by AutoIT – Satish Sahani Sep 25 '15 at 08:50
  • The element in my file is and it is using plupload javascript API to upload file – Satish Sahani Sep 25 '15 at 09:01
  • I resolved this issue refering this link http://stackoverflow.com/questions/15531728/tdd-for-plupload-with-django-splinter – Satish Sahani Sep 25 '15 at 09:47
  • I have one more issue. In this case, a file uploader is using ActiveX control for uploading file(s). The issue is, I am not able to find the element to click. – Satish Sahani Sep 25 '15 at 10:18
0
public void uploadFile(String locatorId, String filePath) {

WebElement fileInput = findElementExplicitWaitWithNoVisbility(By.id(locatorId), true);

fileInput.clear();
fileInput.sendKeys(filePath);}
Padmasankha
  • 103
  • 1
  • 13