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

5
  • 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() Commented Apr 1, 2015 at 12:34
  • Which browser you are using? Commented Apr 1, 2015 at 12:40
  • Input type is file. Then how to do? there is another import button also Commented Apr 1, 2015 at 12:51
  • Can you post the entire Exception that you have received? Visit this link - code.google.com/p/selenium/issues/detail?id=7135, stackoverflow.com/questions/11060033/… which looks like a smiliar issue. Commented Apr 1, 2015 at 14:22
  • @automater Is there any reason why you are using RemoteWebdriver instead of WebDriver? Commented Apr 1, 2015 at 21:25

2 Answers 2

1

Uploading a file using Selenium:

WebElement upload = driver.findElement(By.id("identifier of input tag"));
upload.sendKeys("path to file");
Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

Can you mention how this setting can cause a javascript error?
@Manali : Please check the below links jimevansmusic.blogspot.in/2012/08/… and stackoverflow.com/questions/7278340/… . Hope that will clear

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.