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.

3
  • may be duplicate of stackoverflow.com/questions/9431978/… Commented Oct 10, 2014 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. Commented Oct 10, 2014 at 9:37
  • Was a bit confusing for me with submit button, but also the right answer, thank you Commented Oct 10, 2014 at 9:57

1 Answer 1

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

Use this it works for you Good Luck...

Sign up to request clarification or add additional context in comments.

Comments

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.