Python, JavaScript, C#, PowerShell, or Script-Free?
Computers are great at repeating mundane tasks so that users don't have to. Traditionally, though, you needed a computer science degree to make them do it. However, robotic process automation (RPA) makes it far easier to record and repeat those tasks, creating new opportunities for non-techies across the organization and taking the heat off the IT department.
Let's look at how to automate a login to a website and download a file. It's a task that users do manually every day to retrieve everything from procedure manuals to bug reports.
Writing a Script to Login to a Website and Download a File
Traditionally, you'd automate this two-part process by writing a script using one of the popular languages available to developers, such as Python, Java, C#, or PowerShell.
There's a little work involved in using Python to log in to a website and download a file. The most obvious, but least successful way to do it is to use the Python requests library to access the URL in the login form's action attribute. That means manually reading the page source to find that URL and then passing it along with the values for the username and password through a requests.post instruction.
In Java, you can do something similar using the HttpURLConnection class, while C# coders might use the HttpWebRequest and HttpWebResponse classes. Those using PowerShell to log in and download a file might start by opening their browser as an object, using the Navigate action to reach the login URL, passing in the username and password, and then using click() to hit the login button.
These are basic login approaches, though, and prone to failure. Depending on the login form's structure, you might not be able to use them at all. For example, some sites will insist that your request includes url-encoded session tokens, leaving you with a 400 Bad Request response when you fail to pass them.
This is why many scripted attempts to automate website logins fail at the first hurdle.
Challenges With Login to a Website and Downloading a File
Go Code-Free to Login to a Website and Download a File
The alternative to scripting is to use an RPA tool that captures all these steps graphically. Fortra's Automate provides a step recorder that allows for do-it-yourself UI-driven automation by capturing a user's interactions on browser-based or desktop applications. Each new action is a step that the user can edit at any time using simple dialog boxes without writing any code. Here's how you can use Automate to login to a website and download a file:
- Users can begin by selecting an 'open web browser' action from the GUI Recorder menu and entering the URL that they want to surf to. The tool automatically waits for the entire page to load, and allows users to enter an optional wait time, just to be sure that everything has loaded before proceeding.
- The tool follows the user’s interactions, recording clicks on individual fields in a form. The user can then enter his/her email address, select the password, and click the page's 'log in' or 'submit' button. The tool records these steps separately and does not use static screen coordinates in the process.
- Unlike roll-your-own scripting solutions, Automate stores passwords in a secure central repository. It protects these passwords, so that not even administrators can view them, and only authorized users can access them.
- Once logged into the site, the user can simply enter the URL for the file to download or mimic user navigation if necessary. When the browser reaches the file location, they can enter specific mouse clicks and keystrokes to simulate themselves issuing a 'save' command and can even open the file afterwards. The tool also offers scraper functionality that can parse tables, filenames, and link positions on a page.
- Users can enter exception handling steps to deal with different header responses and take proactive action such as sending an email if any step of the automation fails, automatically incorporating informative exception information into the email.
- After recording an automation task, users can schedule it to run via a simple workflow, which can contain other automation tasks or stand alone. It can run on any system in the network that the user has access to, and execution can be dynamically load balanced among various systems as well.
Advantages of No-Code Automation
One advantage of Automate is that while it's a no-code solution, each step of an action is in human-readable form and can be tested for immediate feedback. This allows users to review and edit the steps where necessary, move steps around, and/or copy them. They can reuse these steps for different sites, altering the parameters and editing steps to quickly customize their automation. Enterprise RPA solution also allows users to share scripts with others via a central database.
If you're a developer, scripting automations like webpage logins and file downloads can be fun. It takes a lot of problem solving and can often feel like you're trying to outwit the website's original developer. But most business users don't have the time or skill for such an undertaking. Graphically-driven RPA helps them to automate things quickly and easily, leaving them to get on with their real work, while the Automate software takes care of the rest.
Get Started with Automate RPA
Start delivering powerful UI-driven automation with robust recordings for your desktop and browser-based applications. Try Automate free for 30 days.