The world revolves around the internet. It's absolutely insane on how long we sit on the internet viewing cat pictures. Interacting with everything on the internet can be a time consuming process. So why not automate the parts you dislike?
Let's take putting a purchase order in at a company you work for. Eventually filling in the exact same information over and over gets old. Typing in my name, email, address, who is approving this, and the million other questions that never change finally got on my nerves. It takes me ~5-10 minutes per purchase order to get it filled out. I have to go look up the vendor rep's information to put it into the form. It's a hassle. I could save all the info in a word doc and copy and paste it, but that doesn't save much time.
So on the journey of automating as much of my job as I can I decided this task will be perfect. I fired up Google and learned how to interact with the different webpages around the world in Python. It's actually incredibly easy!
First off you're going to need Python installed if you're gonna try it with the code I provide. Second you'll need to get familiar with the Selenium documentation. Selenium also works with other languages and the concepts will be the same. Selenium is going to be the framework you use to automate the interaction between your script and the webpage. You will need to download the drive for the browser you want to use. You can select Chrome, Edge, Firefox, and Internet Explorer.
First things first lets get everything imported into our example.
This will get you started with the basics. From there we need to do a few other things to get the base functionality. You need to make sure that the driver you installed is in the path variable or in the same location as your .py file. For this example we will be using Microsoft Edge.
The following code will open a web page in Edge and go to google.com. From there it will look at the HTML code and find the element you specified and then send the input you selected.
So lets break it down.
The first line tells the script that it will be using edge and needs to reference the driver for Edge.
The second line will open the webpage you want to use. For this example it is for Google.
The third line tells the script to find an element named "q". At this point in time "q" is the search field for Google.
The fourth line then clears the search field. You want to do this to ensure nothing is populated in it already.
The fifth line then enters in Snoozey.io to the search bar on Google.
The final line will then look for an element named "btnK' which happens to be the search button, and then it clicks for you.
With this basic knowledge you can now fill in and click all kinds of things on a web page. It won't take long and you'll be automating all kinds of different webpages. Take it for a spin and let us know in the comments what kind of stuff you're automating!