none
SWFUpload in PowerShell RRS feed

  • Question

  • Hey Scripting Guys, I am trying to use PowerShell to automate the process of loading files to a website.

    The process has four steps. The first three steps require the user to fill out information via textboxes, textareas, comboboxes, or radiobuttons and then click a button to proceed to the next step. The fourth step is the uploading step (described in the next paragraph). Each step is on a different screen (the form remains the same, the items on the form change).  I have automated the first three steps of the process where I use getElementbyID method.  However, the fourth step uses SWFUpload utility to upload multiple files and is where I am getting stuck.

    The fourth step is the uploading part. So to manually upload the files, the user must click an "Upload button", which brings up an Open File dialog box. The user must then navigate to the correct folder location and select the files. After the files are selected, the user clicks an Open button, which then uploads the files to the website. The "Upload button" is not actually a button, but is of type "application/x-shockwave-flash". The ID of the "Upload button" is "SWFUpload_0". I Googled SWFUpload and it looks like it is a tool used to upload files to a website, which includes a combination of Flash and JavaScript.

    I can create a PowerShell object from the "Upload button" and have tried to change some of the properties (mainly .outerHTML) with no success.

    Can anyone shed some light on how this SWFUpload works and/or how it can be manipulated in PowerShell? I'm hoping there is a .click() or something equivalent to trigger the "click" action the user would perform to kick of the SWFUpload utility.  A working example would be great. 

    Thanks

    Here is the HTML of the "Upload button":

    <object id="SWFUpload_0" type="application/x-shockwave-flash" data="../js/swfupload.swf?preventswfcaching=1431604321159" width="61" height="22" class="swfupload"><param name="wmode" value="transparent"><param name="movie" value="../js/swfupload.swf?preventswfcaching=1431604321159"><param name="quality" value="high"><param name="menu" value="false"><param name="allowScriptAccess" value="always"><param name="flashvars" value="movieName=SWFUpload_0&amp;uploadURL=%2FPublish%2FPublishUpload.aspx&amp;useQueryString=false&amp;requeueOnError=false&amp;httpSuccess=&amp;assumeSuccessTimeout=0&amp;params=DrawingNumber%3D24392%26amp%3BUploadGroup%3D3D&amp;filePostName=Filedata&amp;fileTypes=*.stp%3B*.txt%3B*.dwf%3B*.dwfx&amp;fileTypesDescription=STP%2C%20TXT%20and%20DWF%20Files&amp;fileSizeLimit=512000&amp;fileUploadLimit=0&amp;fileQueueLimit=0&amp;debugEnabled=false&amp;buttonImageURL=%2FPublish%2F..%2Fjs%2Fswfupload_img.png&amp;buttonWidth=61&amp;buttonHeight=22&amp;buttonText=&amp;buttonTextTopPadding=0&amp;buttonTextLeftPadding=0&amp;buttonTextStyle=color%3A%20%23000000%3B%20font-size%3A%2016pt%3B&amp;buttonAction=-110&amp;buttonDisabled=false&amp;buttonCursor=-1"></object>

    Here is my PowerShell script:

    # Getting user's username & password to provide the logon information to the website.
    $cred= Get-Credential

    # Creating new IE object, making it visible, and navigating to the website.
    $IE=new-object -com internetexplorer.application
    $IE.visible=$true
    While ($ie.busy –eq $true) { start-sleep 1 }
    $IE.navigate2("https://gotocorrectwebsite.com")
    While ($ie.busy –eq $true) { start-sleep 1 }

    # Using credentials found earlier to log in to the website.
    $IE.Document.getElementById(“UID”).value = $cred.username 
    $IE.Document.getElementById(“Pwd”).value=$cred.GetNetworkCredential().password
    $IE.Document.getElementById(“submitbutton”).Click()
    While ($ie.busy –eq $true) { start-sleep 1 }

    # Start of the whole process (data entry and upload). Step 1-3 is data entry, step 4 is uploading.
    # Step 1 - data entry
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_txtbox1”).value = “1234567”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_txtbox2”).value = “00”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_rb1”).checked=$true
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_btn1”).Click()
    While ($ie.busy –eq $true)
    { [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") 
    Start-sleep -seconds 1
    }

    # Step 2 - data entry
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtarea1”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_btn2”).Click()
    While ($ie.busy –eq $true) { start-sleep 1 }

    # Step 3 - data entry
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtbox3”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtbox4”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_combobox1”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtbox5”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtbox6”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_rb2”).checked=$true
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_combobox2”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtbox7”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtbox8”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtbox9”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_combobox3”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtarea1”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtarea1”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtarea1”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtarea1”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtarea1”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_txtarea1”).value=”Value”
    $IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“ctl00_ContentPlaceHolder1_btn3”).Click()
    While ($ie.busy –eq $true) { start-sleep 1 }

    # Step 4 - uploading files to website
    # This is the part that I am getting stuck on. This is the "Upload button".
    # I created the variable $asd to verify that I could create an object from the "Upload button" and to see what Methods/Properties it has.
    $asd=$IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“SWFUpload_0”)

    .outerHTML property of $asd variable:

    <OBJECT id=SWFUpload_0 class=swfupload data="../js/swfupload.swf?preventswfcaching=1431606587083" width=
    61 type=application/x-shockwave-flash height=22 SelectFile="null" SelectFiles="null" StartUpload="null" 
    ReturnUploadStart="null" StopUpload="null" CancelUpload="null" RequeueUpload="null" GetStats="null" SetS
    tats="null" GetFile="null" GetFileByIndex="null" AddFileParam="null" RemoveFileParam="null" SetUploadURL
    ="null" SetPostParams="null" SetFileTypes="null" SetFileSizeLimit="null" SetFileUploadLimit="null" SetFi
    leQueueLimit="null" SetFilePostName="null" SetUseQueryString="null" SetRequeueOnError="null" SetHTTPSucc
    ess="null" SetAssumeSuccessTimeout="null" SetDebugEnabled="null" SetButtonImageURL="null" SetButtonDimen
    sions="null" SetButtonText="null" SetButtonTextPadding="null" SetButtonTextStyle="null" SetButtonAction=
    "null" SetButtonDisabled="null" SetButtonCursor="null" TestExternalInterface="null"></OBJECT>
    • Edited by wallpke Thursday, May 14, 2015 12:51 PM
    Thursday, May 14, 2015 12:34 PM

Answers

  • I did not find a way to work with SWFUpload in PowerShell, but I was able to find three work-arounds.

    1.) SendKeys

    2.) Mouse-click function via http://stackoverflow.com/questions/12125959/power-shell-how-to-send-middle-mouse-click

    3.) WASP https://wasp.codeplex.com/

    I chose to use SendKeys because to use a mouse click, you must also move the mouse. This is possible, but it is so easy to nudge the mouse which would re-posisiton the mouse off of the button.

    SendKeys allows the user to send keyboard keys to the computer without the user acutally doing anything. I used SendKeys to tab to the "Upload button", click it, navigate thru the Open File dialog box to select the files, and finally click the Open button to complete the upload.

    There are some drawbacks to SendKeys, however. SendKeys will send the key(s) only to the window that is in the foreground.  So if you are running your script and your computer sends you a pop-up message in the middle of it, SendKeys will send the keystrokes to that pop-up message.

    SendKeys syntax:

    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")


    • Edited by wallpke Thursday, May 21, 2015 2:21 PM
    • Marked as answer by wallpke Thursday, May 21, 2015 3:03 PM
    Thursday, May 21, 2015 2:21 PM

All replies

  • Not likely that anyone will go over all of this impossible too read text for you.

    I recommend asking a simple question.  What is it that you want to do? What error are you getting?


    \_(ツ)_/

    Thursday, May 14, 2015 1:42 PM
  • Having issues getting SWFUPload to trigger.

    Here is where i get stuck

    # Step 4 - uploading files to website
    # This is the part that I am getting stuck on. This is the "Upload button".
    # I created the variable $asd to verify that I could create an object from the "Upload button" and to see what Methods/Properties it has.
    $asd=$IE.Document.getElementById(“ctl00_ContentPlaceHolder1_popupPublishDrawing_ifPopup”).contentWindow.document. getElementById(“SWFUpload_0”)

    any ideas or examples to get this to trigger?

    Thursday, May 14, 2015 2:23 PM
  • No idea what you are asking.  You cannot create objects in a remote webpage.  You can get the html for the page or for the element on the page and to some degree you can set values in the page.  In some cases you can fire events.  You cannot create objects.


    \_(ツ)_/

    Thursday, May 14, 2015 2:49 PM
  • Consider that, if a web page could independently open and upload a file how secure would your system be.  You can fire some click events by calling the  click method on the button but you will not likely be able to upload a file doing this.


    \_(ツ)_/

    Thursday, May 14, 2015 2:51 PM
  • I have the HTML for the element and can create a PowerShell object from that element (this isn't necessary, but I wanted to make sure that I had the correct element ID). From here I would like to fire the event that puts this element into action (in this case upload files to a website). To my knowledge SWFUpload is used to upload files to a website. I would like to figure out how to fire whatever the event inside SWFUpload is so that the file loading can take place within PowerShell so a user will not have to load 500+ files.
    Thursday, May 14, 2015 4:19 PM
  • This isn't a question for this forum, as you're really asking for custom support on an open-source third-party component. You will need to ask the authors of the component if what you're wanting to do is possible.


    -- Bill Stewart [Bill_Stewart]

    Thursday, May 14, 2015 4:37 PM
    Moderator
  • I have the HTML for the element and can create a PowerShell object from that element (this isn't necessary, but I wanted to make sure that I had the correct element ID). From here I would like to fire the event that puts this element into action (in this case upload files to a website). To my knowledge SWFUpload is used to upload files to a website. I would like to figure out how to fire whatever the event inside SWFUpload is so that the file loading can take place within PowerShell so a user will not have to load 500+ files.

    I do not see where you are creating anything.  You are referencing an element on an IE page.  You are trying to stuff controls on the page with values and cause the page to be posted back to the server.

    As noted above, this Is not likely to work even if you call the correct controls click method.  Uploading and downloading like this would be a violation of the  security restrictions for IE and Windows.  Just think about how easy it would be for a web page to steal all of your data if this were possible.

    Any web site that wants you to automate this will provide an API for uploading and downloading files.  Downloading can and uploading can be done with System.Net.WebClient if the website allows it.


    \_(ツ)_/

    Thursday, May 14, 2015 4:48 PM
  • I did not find a way to work with SWFUpload in PowerShell, but I was able to find three work-arounds.

    1.) SendKeys

    2.) Mouse-click function via http://stackoverflow.com/questions/12125959/power-shell-how-to-send-middle-mouse-click

    3.) WASP https://wasp.codeplex.com/

    I chose to use SendKeys because to use a mouse click, you must also move the mouse. This is possible, but it is so easy to nudge the mouse which would re-posisiton the mouse off of the button.

    SendKeys allows the user to send keyboard keys to the computer without the user acutally doing anything. I used SendKeys to tab to the "Upload button", click it, navigate thru the Open File dialog box to select the files, and finally click the Open button to complete the upload.

    There are some drawbacks to SendKeys, however. SendKeys will send the key(s) only to the window that is in the foreground.  So if you are running your script and your computer sends you a pop-up message in the middle of it, SendKeys will send the keystrokes to that pop-up message.

    SendKeys syntax:

    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")


    • Edited by wallpke Thursday, May 21, 2015 2:21 PM
    • Marked as answer by wallpke Thursday, May 21, 2015 3:03 PM
    Thursday, May 21, 2015 2:21 PM