1

I have to click on an element to upload a CSV file with Selenium WebDriver in JUnit. The input looks like this:

<input type="file" name="upload0" size="56" value="" id="DateiImportSchritt2Csv_upload0"/>

If I click on that input element an OS window opens where I have to choose my file to upload. My problem is that if I use Selenium for clicking the input like this:

driver.findElement(By.xpath("//div[@id='wwctrl_DateiImportSchritt2Csv_upload0']/input")).click();

It does open the OS window, but freezes my whole test without any Exceptions. If I close the window manually, my test continues.

On another place in my code, I have to download a file. It is very similar, except it's not an input element but an anchor element (<a>) and it works fine there.

So how to click an input element which opens an OS window without freezing my test? Also tried submit(), but even the window does not open with that method.

I'm using:
Windows 7
Firefox 32.0.3
Selenium WebDriver 2.43.1
JUnit 4

Edit:
The whole div element looks like this:

<div class="group " id="wwctrl_DateiImportSchritt2Csv_upload0">
<label id="label_DateiImportSchritt2Csv_upload0" for="DateiImportSchritt2Csv_upload0">
<span>CSV-Importdatei für Ranglisten auswählen</span>
</label>
<p class="labelInfo" id="help_DateiImportSchritt2Csv_upload0">

    Bitte wählen Sie eine für den Import bestimmte Datei aus.

</p>
<input type="file" name="upload0" size="56" value="" id="DateiImportSchritt2Csv_upload0"/>
</div>

There is no submit button. The input is also not used for typing, you can only click on it to open a window.

Maze
  • 156
  • 10
  • may be duplicate of http://stackoverflow.com/questions/9431978/one-solution-for-file-upload-using-selenium-webdriver-with-java – Chetan Oct 10 '14 at 09:37
  • 1
    You have an input element, do you also have a 'submit' or similar button? You can typically work around the upload issye by sending the full file path to the input element using .sendKeys() and then clicking on the submit button. – Mark Rowlands Oct 10 '14 at 09:37
  • Was a bit confusing for me with submit button, but also the right answer, thank you – Maze Oct 10 '14 at 09:57

1 Answers1

2
driver.findElement(By.xpath("//div[@id='wwctrl_DateiImportSchritt2Csv_upload0']/‌​input")).sendKeys("Your path");

Use this it works for you Good Luck...

Naveen Kulkarni
  • 233
  • 2
  • 17