Automate Academy Tasks
Automate Desktop

Web Browser Automation: Best Practices

Chapter 8 | Automate Tasks

When automating an application that has a web browser as a user interface, it can sometimes take some trial and error to find the right actions to use. Pat Cameron, Director of Automation, shares the best practices to use when creating web browser automation tasks. In this video you’ll learn:

  • How to visit a web browser and determine the best actions to use for your task
  • The most commonly used actions for web browser automation:
    • Web Browser Action: automate the opening, navigating in, or closing of a browser
    • Interactivity Action: replicate moving a mouse to objects to click links and buttons
    • Input Action: send keystrokes and function keys, as well as clicking links and buttons
    • Window Action: controls windows including opening, closing, and moving windows
    • Wait Action: waits for the occurrence of a specific event or occurrence before continuing with a task

Watch this chapter now to learn how to get started.

 

Transcript

Pat Cameron:                    When automating an application that has a web browser for a user interface, sometimes it a takes little trial and error to get the right actions to create that automation, it will depend on how the webpage is designed, what it was created with, and how those elements are designed. Sometimes the web browser application can't see it on the page, [00:00:30] so then we can take a look at using some of our other interactive actions such as Interactivity, Input, we'll also taker a look at the Window Action and the Wait and how we can make our task most efficient.

                                                I'm gonna create a task here that works with our applications that has a web browser interface. So, the first thing that we one to do is use that web browser action in order to open up the web page. So, we've [00:01:00] got the link, the URL for that application, and we'll just go ahead and run that, and that's gonna bring up the first page. Now, what we want to do is find the username and the password fields and enter that information in to those fields. So, we'll go back to the task and we'll use that web browser action to set value, that's the first thing we're gonna try. So, we'll find the webpage, and it will highlight it in green, can't see that here, but it does, [00:01:30] and then we'll try to pinpoint those elements.

                                                Now you see, as I move my cursor over the screen, it's having a hard time finding those fields specifically. So, I'm gonna go ahead and cancel this and the first one that I'm gonna try is Interactivity, that's usually your best bet. So, I'm gonna use the Set Text with Interactivity, drag that over, and I'm gonna find that field. So, as you saw, Interactivity didn't have any trouble [00:02:00] at all finding that field, I'll enter the text that what to set for that user name, then we'll go ahead and run this so that you can see how it works.

                                                So, I close up the website and just run the task, run both of those actions, and now it's gonna up the URL and it's gonna add demo into the user name. I'm gonna use that same action then to put the password into the password field. I won't even try using the web browser, [00:02:30] if it couldn't find the username, probably wouldn't be able to find the password as well. So, I'll find the field, it pulls back the information about that field and that element, all of those properties, it also finds the X and Y coordinates, but we don't need to use those, and then I'm just gonna putt the text in here.

                                                Alright, so let's test this now. I'll go ahead and close up the website that I've got open here, [00:03:00] and we'll go ahead and run all three of these steps to make sure that they run correctly. You can see it entered demo and password, and the next thing that we need to do is find that Log In button and press that. So, we will try the Web Browser application again, or action again, it's got a click action. So, we'll find the browser, and then we'll try to pinpoint that button, [00:03:30] and as you can see here, I'm having the same issue, it's not able to find that button. So, I'm gonna go ahead and try another action for that.

                                                So, in this case, couple things that I can do. I'm gonna go back to Interactivity, that is usually the most responsive, and so it's got a Press Action. So, now I can use that magnifier just to find that button that I want to press. So again, it will pull [00:04:00] back all of the properties for that button, and we'll give it a go and see if that runs correctly. Let's go ahead and run it, opens it up, enters my user and password and then presses that Log In. So, now we've logged into the application itself.

                                                Just to show you that there are a couple of different ways that you can do this, I'm gonna go ahead and disable this Press Object [00:04:30] and show you another way that you could find that button and click on it. Again, it's gonna depend on your applications, so you might have to try a couple of different things. So, I'm gonna use Interactivity again just to move the mouse to that object, to that Log In button. So, I'll drag it over. Oh, I got to open up the website. Now, I've got my demo and my password entered, so I'll take that and move the mouse to that Log In [00:05:00] button. We'll just find the button, and again, Interactivity is doing a good job of finding all the elements here. Then, we'll go ahead and save that, and then I'm gonna use one of the Input actions. This can be used for entering text in a field, entering key strokes, I'm gonna use it to click the left button, and I just need to do a single click. So, I can just add that to the list as well.

                                                And now [00:05:30] if we go ahead and run this task, you'll see that we get the same result, we've just used some different actions to in order to get there. So, whatever is most efficient for the application that you are running is the way to go. Now, the next thing that I want to show you is that sometimes, especially if you're opening up a website, there might be some type of a delay when it goes to open, and then it's gonna start setting text right away, and you don't [00:06:00] really want to do that until that page is opened and focused. So, I'm gonna go ahead and try to run it again, and you can see here, it's having a hard time opening up that site. So, I got an error that it couldn't the window to enter the text because it wasn't open to that page all the way yet.

                                                So, what I want to do is put in a delay, and so if we take a look at some of the Wait options that we have, I don't want to wait for a duration because [00:06:30] I don't know if it's gonna be one or two or three seconds. I'm gonna wait until that window is open, so I got to bring up the winder so that I can find it, highlight it once we get it open. So, I'm gonna bring over the Wait, For Window up underneath the Open URL, find that window, and then it'll pull in the window name, etc, and what I want to do for the Action is instead of just Waiting [00:07:00] for the Window to Open, Waiting for it to Gain Focus. Now I know it's gonna be ready for me to start entering text into those fields.

                                                So, keep those in mind. Instead of using a duration because you never really know what the durations is gonna be, now I'm gonna be assured that it's not gonna start entering that text until that window is open and it's ready for me to start entering the text in there and logging into that application. So, hopefully those are a few tips to help [00:07:30] you with your web browser automation and Interactivity.

Ready for the next chapter?

Chapter 9: PDF to Excel