0

I have browse button to browse for the file. After browsing there is a import button which will actually import the file. I'm able to browse the path using the following code:

public static void uploadFiles(String object, String data) {
            try {
                String filemode="";
                Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
                String browsername = cap.getBrowserName();
                //System.out.println(browsername);
                if (browsername.contains("chrome")){
                     filemode= "Open";
                }
                else if (browsername.contains("firefox")){
                     filemode= "File Upload";
                }
                else if (browsername.contains("explorer")){
                     filemode = "Choose File to Upload";
                }
                String EXE_FILE=DriverScript.EXE_FILENAME;
                String[] command={EXE_FILE,filemode,data};  
                Runtime.getRuntime().exec(command);
                Thread.sleep(5000);

            } catch (Exception e) {

            }
        }

But when I click on the import button after that "JavaScript error (WARNING: The server did not provide any stacktrace information)" exception is thrown. EXE_FILE is the path to Fileload.exe which is used for browsing

automater
  • 3
  • 2
  • Please add the html code which specifies the type of tag "input". If the input type is 'file' then the upload can be done by using sendKeys() – LittlePanda Apr 01 '15 at 12:34
  • Which browser you are using? – Rupesh Shinde Apr 01 '15 at 12:40
  • Input type is file. Then how to do? there is another import button also – automater Apr 01 '15 at 12:51
  • Can you post the entire Exception that you have received? Visit this link - https://code.google.com/p/selenium/issues/detail?id=7135, http://stackoverflow.com/questions/11060033/selenium-webdriver-error-for-ie which looks like a smiliar issue. – LittlePanda Apr 01 '15 at 14:22
  • @automater Is there any reason why you are using `RemoteWebdriver` instead of `WebDriver`? – Saifur Apr 01 '15 at 21:25

2 Answers2

1

Uploading a file using Selenium:

WebElement upload = driver.findElement(By.id("identifier of input tag"));
upload.sendKeys("path to file");
LittlePanda
  • 2,496
  • 1
  • 21
  • 33
1

Remove capability INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS if you're using it in your test code and manually set your IE protected mode settings to be the same for all zones. It should fix the problem.

Rupesh Shinde
  • 1,933
  • 12
  • 22
  • Can you mention how this setting can cause a javascript error? – LittlePanda Apr 01 '15 at 14:23
  • @Manali : Please check the below links http://jimevansmusic.blogspot.in/2012/08/youre-doing-it-wrong-protected-mode-and.html and http://stackoverflow.com/questions/7278340/nosuchelementexception-is-occurred-during-implementation-of-internetexplorerdriv . Hope that will clear – Rupesh Shinde Apr 01 '15 at 14:43