Issues with script to automate file upload to a website

Welcome Forums General PowerShell Q&A Issues with script to automate file upload to a website

Viewing 1 reply thread
  • Author
    Posts
    • #279468
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Scenario:  At work we have a file that gets generated daily to add new users, and the process is *almost* entirely automated, except that someone has to login to the vendors website each day and upload the file that gets generated.  I’m trying to write a powershell script to automate that last piece as well.

      Issue:  So far I’ve successfully gotten my script to open a visible IE object, navigate to the login page, login, parse through the webpage and a few iframes to get to the step where I choose the file to upload.  At this point, if I have the script ‘click’ the Browse button, a file upload dialog appears, at which point my script is paused until the dialog box is closed.

      Unfortunately because the script gets paused, I cant seem to use Sendkeys to enter the file name and hit Enter.  To get around this, I’ve manually set the variables storing the file path and file name for several elements on the iframe window and form.  The problem is that I must be missing something, my guess is that the form post action isn’t actually getting performed, so the Next button isn’t enabled.

      If I manually enable it and click Next, it throws out an error with no real details.  I’m open to any solution for handling this issue.

      I’ve also tried to Invoke a web request to the form to set the file path and perform the post action and it returns a 200 status (Ok), but when I do that it doesn’t seem to be invoking the form submit in the open ie object, and the user import process is multipart and spans about 3-4 different steps/iframes, so successfully invoking that one form submit doesn’t really help me if I can’t do it in the open ieobject the script is working with.

      Is there anyway that I get get the script to work with the filebrowse dialog box that website opens, or anyway I can perform the form post action within the active IE object created by the script?

    • #279633
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,986
      Helping Hand
      Rank: Community Hero

      That is not an ideal process to automate. Have you asked the vendor if there are options to do direct uploads via SFTP or another method rather than stepping through a webpage wizard?

      Would avoid the IE and SendKeys. Invoke-WebRequest is a better way to interface with the website and there should be no need for the IE object.

      https://stackoverflow.com/questions/36268925/powershell-invoke-restmethod-multipart-form-data

Viewing 1 reply thread
  • You must be logged in to reply to this topic.