Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've found a solution for this; it comes with some caveats but it works for my situation. Hopefully it will help you too.</p> <p>The biggest caveat is that I only know that it works with the current version of AjaxUploader as downloaded today. I'd been using an older version that worked differently; I can't specify a version number since CuteSoft seem pathologically inclined to make the version numbers of AjaxUploader almost impossible to figure out. I can't find a version number for the current version OR the older one that I was using.</p> <p>The other caveat is that it relies on there only being one AjaxUploader control on the page at a time. It appears that AjaxUploader DOES create an <code>&lt;input type='file'&gt;</code> element, but it's left dangling in a div at the top of the <code>&lt;body&gt;</code> tag, without any id or name attribute or anything else to link it to a particular uploader. I'm not sure what AjaxUploader does when more than one of it are present: maybe it creates multiple file inputs and tracks which is which by javascript; maybe it shares one. For my situation I didn't need to solve that part so I didn't try it.</p> <p>Anyway, the trick is to find the file input as follows:</p> <pre><code>webDriver.findElements(By.cssSelector("body &gt; div &gt; input[type='file']")).get(0).sendKeys(fileName); </code></pre> <p>Note that the selector here has nothing to do with the ID or any other characteristics of the particular upload button you're using. It's just "the first file input inside a div directly inside the body tag". That's where AjaxUploader inserts its file input.</p> <p>There appears to be no need to interact with any of the rest of the UI, including the Browse button: <code>sendKeys</code>ing the filename to the right file input causes the upload to begin immediately. (This is an edit; I originally thought that clicking the button was necessary too but it doesn't seem to be)</p> <p>Note that to make sure the timing of your test works correctly, you probably want to follow this click up with a wait operation that waits until the file has finished uploading (eg by waiting for the HTML that the AjaxUploader inserts after uploading is complete) before proceeding to whatever you want to do next.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload