Web automation in python for beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when i was absolute beginner in programming the way how programming tutorials and classes used to get started is first you spend months in learning the basics and after that you print a whole lot of patterns with stars with alphabets and with numbers and that's it that's pretty much it how you learn programming now although learning all these things are very basic component of mastering a programming language but where's the fun in that and obviously if you take out the fun element out of anything it becomes boring and nobody does a thing repetitively and with the same enthusiasm if the thing is boring now talk about making youtube videos or writing programming or hitting the gym or even playing basketball if you take out the fun element it's not fun anymore now i always like to keep the fun element inside any programming language that i'm teaching or even i'm learning and one of the way by which you can insert this extra fun in python is through automation and not just any automation the web automation it's not really a fancy thing but it's gonna give you so much of the joy and pleasure inside that you're gonna keep doing it you want to let i just want to keep doing it in the web automation there are so many things you can do one of the core essential thing is through the selenium selenium although is a very powerful thing and you can use it for doing various kinds of automation testing but you can also do it for fun elements and fun things like having a script that can log you in into facebook or instagram or can take whatever the updates are there on instagram and can show you on the terminal and a whole bunch of other things that you can do with selenium so let me give you in this video a brief tour of how you can have selenium and can do web automation for fun and for pleasure we'll be using selenium to do some of the basic automation which is absolutely fun and let me show you a couple of commands before we get started so first and foremost open up your terminal and then windows users you really want to type just pip and mac and probably linux users as well you want to type on pip3 so we're going to simply say install celeum there we go so selenium this is how you install it it's absolutely simple to get started pip or pip3 again i want to point this out windows users just pip now in case you are on a mac you might need to have a sudo as well in some cases it might not allow to have a permission especially on the catalina then one more thing that we need to have installed on our system is going to be web driver because we are doing web automation it is required that we have some kind of web driver that can open up our chrome or maybe firefox so i'm going to show you both of them so if you'll just search on the google about the selenium chrome driver uh just a little bit up at the bottom you're going to see this github link so you really want to open that one here and on that where is that there we go and this is here so you can see this is how they mentioned that how you can use the different kinds of drivers and you can have a quick quick installation guide here for the mac it was really simple it was just about uh brute tap and brew cask and this whole big command actually i didn't need to use this one actually uh this one is pretty good brew cask install chrome driver that's all for me in case you are in windows i am pretty sure you are using chocolaty if not why are you not using it just install chocolaty and simply say choco or choco install chrome driver so that's pretty much it and similar for the linux as well make sure you have this because without this things are not gonna work and again installing chocolaty is pretty simple on windows just next next i agree okay yes stuff like that okay now what we're gonna do the plan is really simple i want to open up the website youtube.com and i want to pass on a simple query on that so there's a search box at the top and i really want to type my name and hit this button but through the script so it's not really a rocket science it's pretty easy let's open up a python file just open up any empty python file i have named it as automation.pi i've stored it on my desktop nothing fancy pretty easy so let's go ahead and do that so first and foremost what we really want to do is we want to have this selenium which we have installed so we're going to simply say from selenium i want to import these web drivers so let's go ahead and say hey web driver there we go now once we have this web driver we can actually use them so let's create a variable we're going to call this as simply driver this is going to come from the web driver dot now comes the interesting thing since i have just installed the drivers from the chrome i'm going to just create an object off from that here in case you want to use let's just say firefox the the web driver name is gecko so you might want to install that i'm just happy and fine with the chrome itself and again installing the driver is necessary it's not like you have chrome installed you can just get away with that no installing the driver is necessary to automate now coming up interesting part now you want to make a request so this driver is capable of making variety of requests get post put however you want to say i'm going to simply make a fire up a get request now where this get request is going to go http s column slash youtube.com so this is where i want to fire my request and that's pretty much it as of now so i'm going to just save it come on don't show me these error messages and what i will do is i will run this file here again running the file there are a variety of ways however you want to run your file totally up to you for me it's going to be simple python3 and then the file name which is automation.pi once i hit that it's going to load up a browser which somehow goes on to a other screen but again this is going to be the browser that we are having okay looks nice so as of now this is working nice and very quickly you can see that chrome is being controlled by automated test software yeah that's what i'm doing okay now let's go ahead and do some more interesting stuff actually we can do that just right here so i want to copy something here so right click on the search box click on inspect and select this element so just click on this teeny tiny guy and click on the search box this shows that this input box is selected you simply want to right click copy and i want to copy xpath in this case the full xpath is not required only the xpath will do again it depends a bit more detail talk about how these xpath actually work but right now i think this is a fun exercise here so now i'm going to store that into a variable i'm going to call this as search box it is very important that you name your variable nicely otherwise it's going to be hard to find then this driver has a lot of options to find elements so we are going to use find by xpath find element by xpath there we go and i simply want to paste my xpath into these two codes which is a random string we haven't talked much about the xpath on this channel i'll probably make a video on that okay once i have this search box now i want to type something into this search box i'm going to simply say search box and search box dot send keys is used to type just like that so pretty simple things to remember isn't it and i want to type of course my name here because that's what my channel name is so it's going to be easy to find if i can write my name come on that's too much there we go finally i have written my name okay so that part is all done i can easily find a search box and put some things into the search box but i want to simulate click as well so i'm gonna just go ahead and where is my browser there we go and i want to click on this one here so i need to create another variable i'll just select this one and make sure you're selecting the button right click on this button copy and i want to copy xpath moving back on to this so this one is search button and again search button can be fined by similar things so we're going to simply say driver dot find element by xpath there we go xpath again okay looks nice and looks like i have got the search icon here uh let me just try it one more time hoping that i am selecting the right element selecting the right element is important so copy copy xpath make sure you are actually copying the exact text path don't make a mistake in that okay there we go and paste that yeah i've copied the same thing okay moving further now what we want to do with this search button is we can actually fire up a method that is going to be simply click and just like that really really simple stuff and that's pretty much it we have got we can separate them up here on the first line we are we are firing up a get request then we are searching a search box sending some keys into it then we are looking for a search button and we are sending a click automation there really really simple one so i'm going to just save that and let's try it one more time and i want to automate this one here and there we go it opens up the browser and there we go it loads the browser types and there we go really simple nothing much fancy but it's actually very interesting after that what you really want to do you can wait for a few seconds so that response is complete you can get a list of all these you can get a entire list in an array of all the titles up here so yes this can be done in a very very extensive way but i think these things actually makes me super interesting all the time that i'm able to do all these stuff through programming i just love that part now there are two very important thing that i want to tell you now there are two final notes that i would like to mention here one thing is explore a little bit more in depth about selenium and you're going to enjoy a lot make sure whatever programming you are learning make sure you just apply them in doing your daily tasks it's going to make him absolutely fun so that's thing number one and the thing number two is make sure you hit that subscribe button because it gives me a lot of pleasure and it it is just a fun thing for me so make sure help me to enjoy making these videos as well by hitting that subscribe button and i'm gonna surely catch you up with another awesome video don't just print the patterns make sure you are keeping that fun alive in the programming it is very very essential [Music] the things we [Music] even promised we know
Info
Channel: Hitesh Choudhary
Views: 429,484
Rating: 4.9187818 out of 5
Keywords: Programming, LearnCodeOnline, python, python for fun, python programming, python for beginners, python web automation, python selenium, selenium tutorial, web automation tutorials, selenium web driver
Id: f7LEWxX4AVI
Channel Id: undefined
Length: 11min 1sec (661 seconds)
Published: Tue Jan 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.