24

@Florent B. answered my question in regards to uploading a document where the element wasn't an input type="file" here

Now, I have another document upload section that I cannot get handled properly. There is an overlay on the screen with an input type="submit" button, so I use the solution from the hyperlink above, which does upload the document, however, it doesn't change the status showing a document was uploaded which is required to actually complete the order.

Here is my current code that gets the document uploaded, it just doesn't reflect that in the dialog:

// disable the click event on an `<input>` file
((JavascriptExecutor)getDriver()).executeScript(
    "HTMLInputElement.prototype.click = function() {                     " +
    "  if(this.type !== 'file') HTMLElement.prototype.click.call(this);  " +
    "};                                                                  " );

// trigger the upload
VOrderDetails.uploadReport_btn(getDriver()).click();

// change the visibility of the file input control
WebElement elem = getDriver().findElement(By.id("UploadLib_Uploader_js"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) getDriver()).executeScript(js, elem);

Thread.sleep(1000);

getDriver().findElement(By.cssSelector("input[type=file]"))
      .sendKeys(filePath);

File is not showing uploaded

When you manually upload a document, the document appears like the following showing a Test PDF.pdf file was uploaded and allowing you to complete the order:

enter image description here

Is there a way to "fake" it to show a document has been uploaded on this overlay?

Here is the HTML for this piece:

<div id="divSetComplete" style="width: 594px; display: block; top: 316.5px;" class="MessageBox HideOldProgressBar">
  <div class="DialogTitle">Complete assignment</div>
  <div id="divSetCompleteFields" class="DialogSection dsBorder dsColor">
    <img src="/Images/BlackOne.png" class="dsNumber" alt="">
    <div class="dsCaption">
      <span style="margin-right:2px">Upload the report for <span id="Dialogs_Dialogs_spnOrderAddress" class="VariableText">245 W Chantilly Way</span> to your client, <span id="Dialogs_Dialogs_spnOrderClient" class="VariableText">Automation Test User</span>.</span>
    </div>
    <div class="dsContent UploadFields">



      <div id="Dialogs_Dialogs_divFile">
        <div>
          <div id="divProgressBarFile" class="ProgressBarDiv">
            <div id="pbFile" style="display: inline-block; position: relative;">
              <div id="pbFile_divEmpty" class="EmptyGradient BasicStyling" style="width: 371px; display: inline-block; height: 24px; line-height: 24px;">
                <div id="pbFile_divProgress" class="ProgressGradient" style="height: 22px;">
                  <div class="ProgressBackground BasicStyling" style="width: 371px; height: 22px; line-height: 24px;">
                    <label id="pbFile_ProgressText" class="ProgressText" style="width: 319px; height: 24px;"></label><i id="pbFile_ProgressIcon" onclick="ProgressBar.CancelUpload('pbFile','pbFile_Icon','Dialogs_Dialogs_uplFile',true,'Required');" class="fa fa-times ProgressIcon" style="left: 344px; line-height: 24px;"></i>
                  </div>
                </div>
                <label class="EmptyText PlaceholderText" id="pbFile_EmptyText" style="width: 319px; height: 24px; line-height: 20px;">Required</label><i id="pbFile_Icon" class="fa fa-times EmptyIcon" onclick="ProgressBar.CancelUpload('pbFile','pbFile_Icon','Dialogs_Dialogs_uplFile',true,'Required');" style="line-height: 24px; display: none;"></i>
              </div>
            </div>
          </div>
          <div class="SkinButtonDiv">
            <input type="submit" name="ctl00$ctl00$Dialogs$Dialogs$btnUploadFile" value="Upload report" onclick="HideDialog();" id="Dialogs_Dialogs_btnUploadFile" class="MercuryButton Blue" style="height:24px;width:141px;">
          </div>
        </div>
      </div>
    </div>
  </div>
  <div id="divSetCompleteMessage" class="DialogSection dsBorder dsColor">
    <span id="Dialogs_Dialogs_upSetComplete">
                    <img src="/Images/BlackTwo.png" class="dsNumber" alt="">
                    <div class="dsContent">

                        <div>


<div id="Dialogs_Dialogs_ctlCompleteMessage_divNormal">
    <div class="MercuryField">
        <div class="smFieldLabel">Message to client</div>
    </div>
    <div class="MercuryField">
        <div class="MercuryFieldInput">
            <textarea name="ctl00$ctl00$Dialogs$Dialogs$ctlCompleteMessage$txtMessage" rows="2" cols="20" id="Dialogs_Dialogs_ctlCompleteMessage_txtMessage" class="MercuryInput smNormalComment"></textarea>
            <div id="Dialogs_Dialogs_ctlCompleteMessage_hbStatusMessage_pnlHoverWrapper" class="hoverPopupMenu" style="background-color: white; position: absolute; visibility: hidden; left: 517px; top: 29px; z-index: 1000; display: none;">
    <img src="/Images/QuickListImages/QL.png" id="Dialogs_Dialogs_ctlCompleteMessage_hbStatusMessage_btnHover" class="hoverImageBtn" onclick="MercuryNetwork.Common.Controls.QuickList.HoverButton.onClientClick(this, event);" data-client-event="Event_HoverButton_Click" data-target-control-i-d="txtMessage" data-target-control-client-i-d="Dialogs_Dialogs_ctlCompleteMessage_txtMessage" data-user-data="">
</div>
        </div>
    </div>
</div>
                        </div>
                    </div>
                    <div style="display:none">
                                <input id="Dialogs_Dialogs_uplEnv" name="ctl00$ctl00$Dialogs$Dialogs$uplEnv" type="hidden" autocomplete="off" isuploaderfield="1"><button>Upload&nbsp;a&nbsp;file</button><img uniqueid="ctl00$ctl00$Dialogs$Dialogs$uplEnv" namespace="CuteWebUI" root="/" verticks="635229096420000000" filetoolargemsg="{0} cannot be uploaded!

File size ({1}) is too large. The maximum file size allowed is set to: {2}." windowsdialoglimitmsg="Unable to select so many files at once. The total file name length cannot exceed 32kb." canceluploadmsg="Cancel upload" cancelallmsg="Cancel all Uploads" uploadingmsg="Uploading.." uploadaddonbuttonmode="Auto" advancedoptionnosilverlight="true" uploadtype="Auto" uploadcursor="Auto" uploadtypepriority="Silverlight,HTML5,Flash,IFrame" maxfileslimit="1" uploadedfilecount="0" showprogressinfo="1" progresstexttemplate="%SEND% of %SIZE%; %T% seconds left" panelwidth="360" barheight="20" infostyle="padding-left:3px;font:normal 12px Tahoma;" barstyle="Continuous" borderstyle="border:1px solid #444444;" postbackeventreference="__doPostBack('ctl00$ctl00$Dialogs$Dialogs$uplEnv','')" insertbuttonid="Dialogs_Dialogs_btnUploadEnv" cancelbuttonid="Dialogs_Dialogs_uplEnv__Cancel" progresstextid="Dialogs_Dialogs_uplEnv__ProgressText" progressctrlid="Dialogs_Dialogs_uplEnv__Progress" maxsizekb="51200" extensions="env" inserttext="Upload a file" inputboxcsstext="" contextvalue="!3wEWAQVQXFxzczEuaW50ZXJuYWwuYWQubWVyY3VyeXZtcC5jb21cU2hhcmVkIFN0b3JhZ2VcbWVyY3VyeS5hbGFtb2RlLmNvbVxVcGxvYWRlclRlbXBqJn5!30YJ9bQs4t7i2cbnRNiNu2w!2!2" serverlang="AspNet" id="Dialogs_Dialogs_uplEnvImage_unique" resourcehandler="/CuteWebUI_Uploader_Resource.axd" onload="this.style.display=&quot;none&quot; ; if(!window.CuteWebUI_AjaxUploader_Initialize){var xh=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHttp');xh.open('GET','/CuteWebUI_Uploader_Resource.axd?type=script&amp;_ver=635229096420000000',false);xh.send('');eval(xh.responseText)}CuteWebUI_AjaxUploader_Initialize(this.id);" onerror="this.onload()" src="/CuteWebUI_Uploader_Resource.axd?type=file&amp;file=continuous.gif" style="display:none;"><div id="Dialogs_Dialogs_uplEnv__Progress" style="display:none;">
    <span id="Dialogs_Dialogs_uplEnv__ProgressText" style="display: none;">Uploading...</span>
    <input type="submit" name="ctl00$ctl00$Dialogs$Dialogs$uplEnv$_Cancel" value="Cancel" id="Dialogs_Dialogs_uplEnv__Cancel" style="display: none;">
  </div>
  <input id="Dialogs_Dialogs_uplMismo" name="ctl00$ctl00$Dialogs$Dialogs$uplMismo" type="hidden" autocomplete="off" isuploaderfield="1">
  <button>Upload&nbsp;a&nbsp;file</button>
  <img uniqueid="ctl00$ctl00$Dialogs$Dialogs$uplMismo" namespace="CuteWebUI" root="/" verticks="635229096420000000" filetoolargemsg="{0} cannot be uploaded!

File size ({1}) is too large. The maximum file size allowed is set to: {2}." windowsdialoglimitmsg="Unable to select so many files at once. The total file name length cannot exceed 32kb." canceluploadmsg="Cancel upload" cancelallmsg="Cancel all Uploads"
  uploadingmsg="Uploading.." uploadaddonbuttonmode="Auto" advancedoptionnosilverlight="true" uploadtype="Auto" uploadcursor="Auto" uploadtypepriority="Silverlight,HTML5,Flash,IFrame" maxfileslimit="1" uploadedfilecount="0" showprogressinfo="1" progresstexttemplate="%SEND% of %SIZE%; %T% seconds left"
  panelwidth="360" barheight="20" infostyle="padding-left:3px;font:normal 12px Tahoma;" barstyle="Continuous" borderstyle="border:1px solid #444444;" postbackeventreference="__doPostBack('ctl00$ctl00$Dialogs$Dialogs$uplMismo','')" insertbuttonid="Dialogs_Dialogs_btnUploadMismo"
  cancelbuttonid="Dialogs_Dialogs_uplMismo__Cancel" progresstextid="Dialogs_Dialogs_uplMismo__ProgressText" progressctrlid="Dialogs_Dialogs_uplMismo__Progress" maxsizekb="51200" extensions="xml" inserttext="Upload a file" inputboxcsstext="" contextvalue="!3wEWAQVQXFxzczEuaW50ZXJuYWwuYWQubWVyY3VyeXZtcC5jb21cU2hhcmVkIFN0b3JhZ2VcbWVyY3VyeS5hbGFtb2RlLmNvbVxVcGxvYWRlclRlbXBqJn5!30YJ9bQs4t7i2cbnRNiNu2w!2!2"
  serverlang="AspNet" id="Dialogs_Dialogs_uplMismoImage_unique" resourcehandler="/CuteWebUI_Uploader_Resource.axd" onload="this.style.display=&quot;none&quot; ; if(!window.CuteWebUI_AjaxUploader_Initialize){var xh=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHttp');xh.open('GET','/CuteWebUI_Uploader_Resource.axd?type=script&amp;_ver=635229096420000000',false);xh.send('');eval(xh.responseText)}CuteWebUI_AjaxUploader_Initialize(this.id);"
  onerror="this.onload()" src="/CuteWebUI_Uploader_Resource.axd?type=file&amp;file=continuous.gif" style="display:none;">
  <div id="Dialogs_Dialogs_uplMismo__Progress" style="display:none;">
    <span id="Dialogs_Dialogs_uplMismo__ProgressText" style="display: none;">Uploading...</span>
    <input type="submit" name="ctl00$ctl00$Dialogs$Dialogs$uplMismo$_Cancel" value="Cancel" id="Dialogs_Dialogs_uplMismo__Cancel" style="display: none;">
  </div>
  <input id="Dialogs_Dialogs_uplPdf" name="ctl00$ctl00$Dialogs$Dialogs$uplPdf" type="hidden" autocomplete="off" isuploaderfield="1">
  <button>Upload&nbsp;a&nbsp;file</button>
  <img uniqueid="ctl00$ctl00$Dialogs$Dialogs$uplPdf" namespace="CuteWebUI" root="/" verticks="635229096420000000" filetoolargemsg="{0} cannot be uploaded!

File size ({1}) is too large. The maximum file size allowed is set to: {2}." windowsdialoglimitmsg="Unable to select so many files at once. The total file name length cannot exceed 32kb." canceluploadmsg="Cancel upload" cancelallmsg="Cancel all Uploads"
  uploadingmsg="Uploading.." uploadaddonbuttonmode="Auto" advancedoptionnosilverlight="true" uploadtype="Auto" uploadcursor="Auto" uploadtypepriority="Silverlight,HTML5,Flash,IFrame" maxfileslimit="1" uploadedfilecount="0" showprogressinfo="1" progresstexttemplate="%SEND% of %SIZE%; %T% seconds left"
  panelwidth="360" barheight="20" infostyle="padding-left:3px;font:normal 12px Tahoma;" barstyle="Continuous" borderstyle="border:1px solid #444444;" postbackeventreference="__doPostBack('ctl00$ctl00$Dialogs$Dialogs$uplPdf','')" insertbuttonid="Dialogs_Dialogs_btnUploadPdf"
  cancelbuttonid="Dialogs_Dialogs_uplPdf__Cancel" progresstextid="Dialogs_Dialogs_uplPdf__ProgressText" progressctrlid="Dialogs_Dialogs_uplPdf__Progress" maxsizekb="51200" extensions="pdf" inserttext="Upload a file" inputboxcsstext="" contextvalue="!3wEWAQVQXFxzczEuaW50ZXJuYWwuYWQubWVyY3VyeXZtcC5jb21cU2hhcmVkIFN0b3JhZ2VcbWVyY3VyeS5hbGFtb2RlLmNvbVxVcGxvYWRlclRlbXBqJn5!30YJ9bQs4t7i2cbnRNiNu2w!2!2"
  serverlang="AspNet" id="Dialogs_Dialogs_uplPdfImage_unique" resourcehandler="/CuteWebUI_Uploader_Resource.axd" onload="this.style.display=&quot;none&quot; ; if(!window.CuteWebUI_AjaxUploader_Initialize){var xh=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHttp');xh.open('GET','/CuteWebUI_Uploader_Resource.axd?type=script&amp;_ver=635229096420000000',false);xh.send('');eval(xh.responseText)}CuteWebUI_AjaxUploader_Initialize(this.id);"
  onerror="this.onload()" src="/CuteWebUI_Uploader_Resource.axd?type=file&amp;file=continuous.gif" style="display:none;">
  <div id="Dialogs_Dialogs_uplPdf__Progress" style="display:none;">
    <span id="Dialogs_Dialogs_uplPdf__ProgressText" style="display: none;">Uploading...</span>
    <input type="submit" name="ctl00$ctl00$Dialogs$Dialogs$uplPdf$_Cancel" value="Cancel" id="Dialogs_Dialogs_uplPdf__Cancel" style="display: none;">
  </div>
  <input id="Dialogs_Dialogs_uplFile" name="ctl00$ctl00$Dialogs$Dialogs$uplFile" type="hidden" autocomplete="off" isuploaderfield="1">
  <img uniqueid="ctl00$ctl00$Dialogs$Dialogs$uplFile" namespace="CuteWebUI" root="/" verticks="635229096420000000" filetoolargemsg="{0} cannot be uploaded!

File size ({1}) is too large. The maximum file size allowed is set to: {2}." windowsdialoglimitmsg="Unable to select so many files at once. The total file name length cannot exceed 32kb." canceluploadmsg="Cancel upload" cancelallmsg="Cancel all Uploads"
  uploadingmsg="Uploading.." uploadaddonbuttonmode="Auto" advancedoptionnosilverlight="true" uploadtype="Auto" uploadcursor="Auto" uploadtypepriority="Silverlight,HTML5,Flash,IFrame" maxfileslimit="1" uploadedfilecount="0" showprogressinfo="1" progresstexttemplate="%SEND% of %SIZE%; %T% seconds left"
  panelwidth="360" barheight="20" infostyle="padding-left:3px;font:normal 12px Tahoma;" barstyle="Continuous" borderstyle="border:1px solid #444444;" postbackeventreference="__doPostBack('ctl00$ctl00$Dialogs$Dialogs$uplFile','')" insertbuttonid="Dialogs_Dialogs_btnUploadFile"
  cancelbuttonid="Dialogs_Dialogs_uplFile__Cancel" progresstextid="Dialogs_Dialogs_uplFile__ProgressText" progressctrlid="Dialogs_Dialogs_uplFile__Progress" maxsizekb="51200" extensions="pdf,xml" inserttext="Upload a file" inputboxcsstext="" contextvalue="!3wEWAQVQXFxzczEuaW50ZXJuYWwuYWQubWVyY3VyeXZtcC5jb21cU2hhcmVkIFN0b3JhZ2VcbWVyY3VyeS5hbGFtb2RlLmNvbVxVcGxvYWRlclRlbXBqJn5!30YJ9bQs4t7i2cbnRNiNu2w!2!2"
  serverlang="AspNet" id="Dialogs_Dialogs_uplFileImage_unique" resourcehandler="/CuteWebUI_Uploader_Resource.axd" onload="this.style.display=&quot;none&quot; ; if(!window.CuteWebUI_AjaxUploader_Initialize){var xh=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHttp');xh.open('GET','/CuteWebUI_Uploader_Resource.axd?type=script&amp;_ver=635229096420000000',false);xh.send('');eval(xh.responseText)}CuteWebUI_AjaxUploader_Initialize(this.id);"
  onerror="this.onload()" src="/CuteWebUI_Uploader_Resource.axd?type=file&amp;file=continuous.gif" style="display:none;">
  <div id="Dialogs_Dialogs_uplFile__Progress" style="display:none;">
    <span id="Dialogs_Dialogs_uplFile__ProgressText" style="display: none;">Uploading...</span>
    <input type="submit" name="ctl00$ctl00$Dialogs$Dialogs$uplFile$_Cancel" value="Cancel" id="Dialogs_Dialogs_uplFile__Cancel" style="display: none;">
  </div>
</div>
</span>
</div>
<div class="DialogFooter">
  <div class="MessageBoxButton">
    <a id="Dialogs_Dialogs_btnSetCompleteCancel" onclick="return ButtonVerifyEnabled(this, ResetComplete(true));" class="SkinButton sbGray" onmouseover="ButtonHover(this,30);" onmouseout="ButtonLeave(this);" onmousedown="ButtonDown(this,30);" onmouseup="ButtonHover(this,30);"
    skinheight="30" style="color:Black;width:72px;height:30px;line-height:30px;">
      <div class="SkinButtonLeft"></div>
      <div class="SkinButtonRight"></div>Cancel</a>
  </div>
  <div class="MessageBoxButton">
    <a id="Dialogs_Dialogs_btnSetCompleteOK" onclick="return ButtonVerifyEnabled(this, SetStatusComplete());" class="SkinButton sbBlue" onmouseover="ButtonHover(this,30);" onmouseout="ButtonLeave(this);" onmousedown="ButtonDown(this,30);" onmouseup="ButtonHover(this,30);"
    skinheight="30" style="color:White;width:72px;height:30px;line-height:30px;">
      <div class="SkinButtonLeft"></div>
      <div class="SkinButtonRight"></div>OK</a>
  </div>
</div>
</div>

Here is the HTML after the file upload:

<div id="pbFile_divEmpty" class="EmptyGradient BasicStyling" style="width: 371px; display: inline-block; height: 24px; line-height: 24px;">
  <div id="pbFile_divProgress" class="ProgressGradient" style="height: 22px; width: 100%;">
    <div class="ProgressBackground BasicStyling" style="width: 371px; height: 22px; line-height: 24px;">
      <label id="pbFile_ProgressText" class="ProgressText" style="width: 319px; height: 24px;">Test PDF.pdf</label><i id="pbFile_ProgressIcon" onclick="ProgressBar.CancelUpload('pbFile','pbFile_Icon','Dialogs_Dialogs_uplFile',true,'Required');" class="fa fa-times ProgressIcon" style="left: 344px; line-height: 24px;"></i>
    </div>
  </div>
  <label class="EmptyText " id="pbFile_EmptyText" style="width: 319px; height: 24px; line-height: 20px;">Test PDF.pdf</label><i id="pbFile_Icon" class="fa fa-times EmptyIcon" onclick="ProgressBar.CancelUpload('pbFile','pbFile_Icon','Dialogs_Dialogs_uplFile',true,'Required');" style="line-height: 24px; display: inline-block;"></i>
</div>

I was able to capture the screenshot below once I hit the upload button when uploading a document.

enter image description here

Community
  • 1
  • 1
Dustin N.
  • 785
  • 1
  • 14
  • 32
  • Are you able to identify the 'x' that appears next to the file name once uploaded? If so you could include code to wait for visibility of the 'x'. – Sai Oct 17 '16 at 14:47
  • If I could get the document to appear as uploaded, I would be able to, however, the problem is the document gets uploaded, but it does not get reflected in the dialog. The box remains the same as the first image showing Required – Dustin N. Oct 17 '16 at 14:55
  • Are there absolutely no changes on the UI when the path to the file is entered? – Sai Oct 18 '16 at 14:11
  • No, unfortunately not. The document does get uploaded and attached to the order, but nothing in this screen reflects that at that – Dustin N. Oct 18 '16 at 14:23
  • Could you try waiting for the invisibility of //label[.='Required'] ? – Sai Oct 18 '16 at 14:28
  • Also, unlike the other question referenced initially, the 'Upload report' here is an input. So you could simply use sendKeys to insert the path and wait for invisibility of //label[.='Required'] or the presence of the 'x'. – Sai Oct 18 '16 at 14:32
  • The Required label never changes even though the document is successfully being uploaded. That's the issue I'm trying to overcome. The document does get uploaded to the order, but for whatever reason, nothing on this screen reflects that and just appears as though nothing happened. I cannot just do a sendKeys on this element because it is of the type 'submit' and not 'file'. – Dustin N. Oct 18 '16 at 16:24
  • Shot in the dark here, but had another look at the HTML, and it appears to have an Ajax component associated with the file upload, you could use the code from http://stackoverflow.com/questions/24298925/how-to-checkif-there-are-pending-requests-ajax-and-its-variants-from-browser to ensure that the pending request (file upload) is complete. Might help. – Sai Oct 18 '16 at 17:16
  • Has worked well for a few applications where we had "invisible" processes running and couldn't ascertain whether it was complete or not before proceeding - although it was actually done. – Sai Oct 18 '16 at 17:18
  • This question refuses to get out of my mind :) have one last thought, when you upload it manually, the file name appears with a blue background and the x, so similar to the how JavaScript executor was used to display the input type=file, you could try to insert this within the dom in the same hierarchy - this could trick the ui into replacing "Required" with the actual file making it look the way it should before proceeding? – Sai Oct 18 '16 at 21:29
  • I thought that may work as well and have been trying that this afternoon, but I don't know how to do that. I tried editing the HTML manually, but have been unsuccessful in even getting that to work so far – Dustin N. Oct 18 '16 at 21:37
  • Could you spy on the blue element and paste that portion of the HTML? I'll have a look and see if I can figure something out – Sai Oct 18 '16 at 22:43
  • I have added the HTML that gets changed when a file is uploaded. I tried replacing that directly in the HTML on the page and it did not work. It still showed an error that a document was required. I'm still digging around and will post back with any findings – Dustin N. Oct 19 '16 at 12:08
  • My suspicion is that since these changes via JavaScript aren't committed to the server, when input type=submit is clicked, all changes are lost and the request sent essentially doesn't contain the file. I'll look around for solutions as well and keep you posted. – Sai Oct 19 '16 at 14:08
  • Just to clarify, have you tried clicking on or sending some text to the 'message to client' element after using the JavaScript workaround to upload the file? – Sai Oct 19 '16 at 15:33
  • No, I haven't done that. How would I go about doing that? – Dustin N. Oct 19 '16 at 17:48
  • What's the line on code you use immediately after uploading the file? – Sai Oct 19 '16 at 18:11
  • After I "upload" the file, I have a while loop that checks for the file name to be present in the progress bar. Is that what you are asking? While troubleshooting, I currently don't have anything except for a Thread.sleep(99999) so I can check to see if the file appears, but it never does. I have tried to enter text in the message box after the upload and then click OK, but that throws an error saying a document is requried. Is that what you're asking? – Dustin N. Oct 19 '16 at 19:35
  • Yes that's what I was asking..instead of entering text in the textarea, try and click on the textarea or on some other element in the overlay (just ensure that its not a button) and then wait for the progress bar. So basically, upload, click somewhere, wait and then proceed. – Sai Oct 19 '16 at 19:51
  • Unfortunately that did not work neither. I do appreciate you help, btw. – Dustin N. Oct 19 '16 at 20:11
  • No worries. I'm quite intrigued with the question. There are a few options here: http://stackoverflow.com/questions/12363038/selenium-webdriver-click-on-hidden-elements looking for a site with a similar field to try something else out. Will keep you posted if I find anything else. – Sai Oct 20 '16 at 12:13
  • So once you disable the click event using Florent's JavaScript method, is there an input element that becomes "visible"? Tried using Zamzar.com but that has an input type file which is hidden and changing the z-index did the trick. But in this case I don't see any form of input on the HTML. Also maybe just try clicking on the upload report button again after you've "uploaded" the file and observe behavior. I now feel like there's something simple we're missing. – Sai Oct 20 '16 at 12:42
  • I don't see any input element that becomes "visible" after disabling the click event. I can say after numerous times testing this field, I get a success rate of it actually showing as being uploaded about 5% of the time. About 10% of the time I get an error saying an incorrect form was tried to be uploaded. The remaining 85% it just doesn't do anything. I tried adding a sleep in between all the steps up to 10 seconds thinking maybe it was trying too quickly, but that had no affect. I tried what you suggested and clicked the upload button again after the upload with no luck there neither. – Dustin N. Oct 20 '16 at 16:27
  • I ran a trace of the Nework and it appears it is using CuteWebUI AjaxUploader. I also found this information in the Request Payload after manually uploading the document, I'm just not sure what to do with the info yet or if it is even relevant to the situation. It at least opens up a few more rabbit holes to search the internet for: AjaxUploader ------WebKitFormBoundaryxKdQtcenRx3ZzV6A Content-Disposition: form-data; name="file"; filename="Test PDF.pdf" Content-Type: application/pdf – Dustin N. Oct 20 '16 at 17:01
  • @Sai was able to capture what happens when the upload button is clicked. Not sure if this is helpful in any way, but... – Dustin N. Oct 20 '16 at 18:41
  • 3
    That's actually quite helpful. Once the input is enabled, try the script here http://stackoverflow.com/questions/12363038/selenium-webdriver-click-on-hidden-elements instead of a standard sendKeys and then click somewhere random to ensure that the action is actually performed. That did the trick on zamzar.com. Don't have the code handy at the moment. Will send it to you when I access my system. – Sai Oct 20 '16 at 19:17
  • Man! I thought that was it. It worked the first time around, but now it's just doing the same behavior as before. Am I supposed to run the new js on the Upload button or somewhere else? – Dustin N. Oct 20 '16 at 20:19
  • Run it on the hidden input – Sai Oct 20 '16 at 20:31
  • Ok. That's what I thought, but just wanted to make sure I wasn't missing something. – Dustin N. Oct 20 '16 at 20:36
  • @DustinN. if you're still having issues (unclear from the comments above), you may try sending an ENTER command to the field. Shot in the dark, but that may trigger the browser element events to fire similar to actual user input. Something like... getDriver().findElement(By.cssSelector("input[type=file]")) .sendKeys(getDriver().Key.ENTER); – Paul Bruce Dec 20 '16 at 18:59
  • @DustinN.: Now, since input[type= 'file'] is already enabled, can't you directly getDriver().findElement(By.cssSelector("input[type=file]")) .sendKeys(filePath); and see what happens? – Sakshi Singla Feb 02 '17 at 07:14
  • So, I am suggesting to skip the jsexecutor and just use a plain input type and sendkeys – Sakshi Singla Feb 02 '17 at 08:36

1 Answers1

2

Install Autoit and try the following.

How to install autoit, You can install using this link.

Once you installed.Then do the following things:

Start menu -> All Programs -> AutoIt V3 -> SciTE Script Editor

enter image description here

Copy this and paste there : This is for fire fox

ControlFocus("File Upload","","Edit")
Sleep(2000)
send("test.txt")
Sleep(2000)
send("{ENTER}")

enter image description here

Compile it :

Tools -> Compile or Cntr+F7

Create .exe file from .au3 file:

Start -> All Program -> AutoIt v3 -> Compile Script to .exe

enter image description here

Once you run this .exe file will be created under the folder where .au3 file is located.You need to refer this file in you test code.

My html file

    <html>
<body>
<script>
function uploadOnChange(e) {
    var filename = e.value;var lastIndex = filename.lastIndexOf("\\");
    if (lastIndex >= 0) {
        filename = filename.substring(lastIndex +1);
    }
    document.getElementById('filename').value = filename;
}
</script>
<input id="upload" type="file" onChange="uploadOnChange(this)" />
<input id="filename" type="text" />


</body>
</html>

My Test code :

    import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class FileUploadTest {

    private static WebDriver driver = null;

    @Test
    public void testFileUpload() throws IOException, InterruptedException, IOException {

        driver = new FirefoxDriver();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        driver.get("file:///C:/Users/sv/Desktop/uploadDoc.html");

        driver.findElement(By.id("upload")).click();

        Runtime.getRuntime().exec("<exe file path>");

        Thread.sleep(6000);

        System.out.println(driver.findElement(By.id("filename")).getText());

        driver.close();

    }
}

For more info, Please refer this link

piet.t
  • 11,718
  • 21
  • 43
  • 52
Sudha Velan
  • 633
  • 8
  • 24