2

I am trying to hit a link to attach files to the page. The HTML structure of the page is

<div class="multi_attach_files">
    <span id="WorkkardFileUploader" class="file_uploader">
        <div id="px-widget-1" class="px-widget ui-widget-px">
            <div class="ui-helper-clearfix">
                <div id="px-form-1-input" class="px-form-input">
                    <form id="pxupload1" name="multipleFileUpload" style="" target="pxupload1_frame" action="/multiupload" method="POST" enctype="multipart/form-data" encoding="multipart/form-data">
                        <div class="px-input-button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button">
                            <span class="ui-button-text">
                                <span class="label">Attach Files</span>
                                <span id="dragMsg" class="dragcontainer">Drag Here</span>
                                <input id="wkFileUpload" class="fileupload" type="file" multiple="" tabindex="-1" name="noteFilename" title="Attach Files" style="background-color: transparent;">
                            </span>
                        </div>

I have already tried .sendkeys(), but the element(id="wkFileUpload") is not visible to Selenium.

Can someone please suggest anything?

Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
shikhar
  • 73
  • 1
  • 8

1 Answers1

1

Unfortunately, you can't do that as of now (September 2013, Selenium 2.35.0), because Selenium doesn't support <input type="file" multiple> elements.

There is a feature enhancement request for this made by the project developers themselves, it's just not yet implemented. You can star it there to move it upwards in the priority list.

The bug mentions that some work has been done on it, but I don't think it will be done any time soon. Your best bet is to use AutoIT (Windows only) or the Robot class (will also work only on setups similar to yours) and type the path "blindly" into the dialog:

driver.findElement(By.id("wkFileUpload")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_C);        // C
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_COLON);    // : (colon)
r.keyRelease(KeyEvent.VK_COLON);
r.keyPress(KeyEvent.VK_SLASH);    // / (slash)
r.keyRelease(KeyEvent.VK_SLASH);
// etc. for the whole file path

r.keyPress(KeyEvent.VK_ENTER);    // confirm by pressing Enter in the end
r.keyRelease(KeyEvent.VK_ENTER);

It sucks, but it should work. Note that you might need these: How can I make Robot type a `:`? and Convert String to KeyEvents (plus there is the new and shiny KeyEvent#getExtendedKeyCodeForChar() which does similar work, but is available only from JDK7).

Community
  • 1
  • 1
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
  • Thanks for the response. I will surely give it a try and will get back. Btw I have voted for the issue and hope that it gets fixed well in time for me to use it in current project. – shikhar Sep 17 '13 at 12:53