Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
may be duplicate of stackoverflow.com/questions/9431978/… –  Chetan Oct 10 at 9: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 at 9:37
    
Was a bit confusing for me with submit button, but also the right answer, thank you –  Maze Oct 10 at 9:57

1 Answer 1

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

Use this it works for you Good Luck...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.