Selenium Python Beginner Tutorial - Learn Selenium Python in one video | Step by Step

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome to this session on selenium Python beginner tutorial today we are going to learn how to use selenium with Python and we are going to go very basic so if you do not know Python and it's the first time you are a complete beginner do not worry we will go very basic step by step and we will cover how to download Python on Windows how to install Python how do you install selenium Python libraries how to download IDE which is PyCharm that we will be using for writing our selenium scripts we will create a new project we will add some selenium scripts and then we will run and validate at the end I will also share some useful tips with you so let us begin so step number one should be step one is we have to download Python and let us go to our browser and I am just going to say on Google download Python and let us search and we will get this site let us go here I will also just copy this URL and make it available here and all these nodes you will find in the description below the videos so let me go here and now we have Python 3 and Python 2 so you can take the latest version of whatever Python is available at your time however I have found few compatibility issues with selenium and Python 3 so I'm going to download Python 2 for now and it will download an executable as of now I will cancel it because I already have it and once you have downloaded it step number 2 is you will install Python so let me go to my python installer and here it is so just double click here and it will install python for all users say next and ideally it should it will go in c python so let it be and click Next and Next start installing Python on your system so it can take a few seconds to few minutes and once this is done you can click on to finish and now you can to validate you can go to your C so let me just go to my C folder and here you should get this Python 27 now if you start command prompt on this particular location I can directly go to this address bar and press CMD and enter so this will start my command prompt on this location itself and now I can say Python space - - version this should show me the Python version and if I go to the let me go to the lip and let me go to yeah we have yeah let me go to scripts and here again if I say if space - - version it is not recognized but if I go to here scripts folder and start command prompt here I will say gift space - - version I should get the quick version as well right so pip is the installer manager for python it will help us install and manage all the packages but you can see if I go to a normal command prompt and go to any other location if I say Python space - - version or I say it space - - version I am NOT getting the python version or the paper version which is installed so for that what I will have to do is I will have to set the environment variables so let me exit from here and exit from here and on my my computer's go to right click and go to advanced system settings environment variables and here I will find an environment variable by the name path let me edit this and on Windows 10 you get this kind of an interface but even if you are using any version of windows you can just add the Python library path at the ends so in case you are using the earlier versions of Windows what you have to do is whatever text is available you have to give let us say there is some already text available you have to give a semicolon and then add the Python part so you will have this Python script and then again give a semicolon and add this Python folder like this and just save it in my case because I am using Windows 10 I can directly add it from here I will say new and I will just give the location of C Python 27 and again I will add one more path which is for the scripts folder so these are the two things that you have to add here I will again say new and add and ok and ok and ok and now I can go to any location of my command prompt and say python space - hyphen version or v space - hyphen version and I get this so now I can use Python from any location on my system so make sure you get these messages i will also add these commands here step 2 will be installed and check python is Python and pip is installed successfully and the commands our python space - hyphen version on the command prompt and web space - hyphen version so you can run these commands before installing as well and you should get something like the man not found if python is not installed and then after installing you can again check this should give you these valid results and this should show you the version of python and pip on your system and now we have Python ready now the next step is we have to install selenium fighting libraries so for that you can run a simple command for tape which is pip install - u selenium so let us run this command on our command prompt I will go to my command prompt and say pip install - u selenium and just run this and it will take the latest selenium package for python and it will add the libraries and you can see it has installed selenium 3.5 dot 0 to verify this is the latest one you can also go to the selenium web site which is selenium HQ dot lower g and here if you go to downloads you can see this is the latest version 3.5 dot 3 and in our case also python has installed the latest version and also to verify you can again go to your C and wherever your python is so in my case it is C Python 27 and now if you see you will have this selenium folder and also it should be inside let me go to my lip and side packages and you can see this selenium 3.5 is now here so that means selenium libraries are successfully added and let us see what is the next step and now we have to download some ID for creating our selenium scripts so for Python we can say we can download PI Chan so let me just go to the browser and say download pycharm and you will get here so here you will say you will see this is a professional Edition which is paid but it has a free tyre trial but we also have a community edition for pycharm and you can download this one so just download this so for now I will just cancel this download because I already have it and let me show you I will I have this pycharm Community Edition and I will just run the Installer so you can say next and then you can select the bit size so in my case I have 64-bit operating system also you can go and check so you can go to your my computer do a right click go to properties and here you can get all the details so I have a 64-bit operating system so I'm going to select the 64-bit you can also get both if you want and then just go to next and click on install so it will install the PyCharm IDE on your system so this will take some time a few minutes maybe and once this is done we will have our pycharm on our system so now this is done and you can select to run Python Community Edition as well and say finish and it will open by charm so I am saying do not import anything and say ok and let us wait for pycharm to get started so now here see it gives us some options as well so you can say click to preview and you can select whatever editors and points you want so you can select like whatever these kind of editors you want so I will go with default and I will just say ok and now you can just create a new project here so before we do that let me just write down the steps as well so our step number 3 was install selenium libraries using this command and then we download it PyCharm and let me also add the link to this that I should add this link and this is very easy to use I will just show you how so this is the step number four step four is download pycharm and this is the community edition and this is the link and now step number five is we have to create new project in pycharm so let us do that so I will just click on create new project and here it is asking me to give the project name so I will say this is first selenium test and if you see here it shows us the option to select the interpreter so as of now I have just this Python version on my system and it is already selecting it so I will just say create so you can see it will create the project it will also show you some tips you can go through it it will be very useful but here you can see we have our project created so this is our selenium Python project and now let us go to the next step which is we have to add selenium script so this is step number six adding selenium scripts to the project okay so let us do that so here you can see you can do a right click on this project and then you can go to new and then you can add any of these options so what I have to I have to actually add a Python file but before I do that I will actually add a directory and I will just name this as test so the only thing that I'm doing this is for so that I can manage my tests separately in a folder so this is a good practice you can manage all your you can put all your tests in a separate folder all your libraries in a separate folder and the other things accordingly so now I will do a right-click on this directory which is test and now I will say new python file and here i will say this is let us say test number one and say ok and now we have got this ID which is ready for us to create our selenium scripts so the first thing we have to do is we have to import selenium and it will give you the options directly so you can see this is very interactive I will just select selenium and you can see it is taking it from C Python 27 website packages that are already showed you and from here in fact you have to say from selenium we have to import webdriver so we are going to have webdriver which will be used and as of now you can see this is all greyed out because this library is not used anywhere so let me let me also go and go to the settings and let me go to the editor and let me go to fonts and give some high sized font so that you can see everything I will say okay okay now it is better and now I will say so you can say here driver equals webdriver dot and you can select any browser so let me say I want to test it on Chrome so you can say Chrome and in case you want to test it with any other driver you can say driver dot webdriver dot Firefox or driver equals webdriver dot let us say ie and you will see how exactly it will do in all these powders and then you can say driver dot set page load time outs so it is very intuitive you can just select this and just add any number of seconds so this is the page load time out and in Python it is very easy you do not have to you know write multiple statements like in Java it is very straightforward also if you want to comment out something you can put a hash or add or you can press ctrl + the forward slash on your keyboard it will comment it out so you can do like this and if you want to write a simple print statement you can say print and you can say hello world and you can do a right click and run the test and will print hello world you can say a equals 10 B equals 20 and C equals a plus B and then you can say print C and let us run it again right click and they run the test and you can see this is the outcome and suppose I want to change it to decimal I will say 10.20 and I will say this is as 20.1 0 and now see I have not declared which is end which is float which is decimal like in Java I have just changed it and it should take it by default so I will run it now and you can see the result has 30.3 so it has converted everything itself it has converted C as a decimal number so I do not have to do anything so python is very easy and very straightforward let us come back to our selenium script so for now let me just uncomment the Chrome browser and now here you can say driver dot set paste time of 10 and then you can say driver dot get and here you can add the URL so in our case let us go to [Music] let me go here so I will just say HTTP google.com and here I want to add let us say I want to find the element this search box so I can do a right-click I do get in I will do inspect and you can see these are all the properties and you can see the name is Q here so I will just say find driver dot find element and you can see all these options you can find by CSS ID link text name so I will select name and I will say Q and then I can say dot send keys and whatever text you want to type I will say automation step by step and then I have to click on the search button so let me also again go and see what is the name for the search button I will say inspect and I can see the name as this so I will just copy it here and I will say driver dot find element again by a name and this is the name and I will say this time dot click so these are all the options as soon as you will you know do a dot here you will get all the selenium options of what all you can do right so this time I will just want to click this button so I will say click and then I will say so I can also say I can wait for some time so I can say time for that I will have to import the time libraries I will say import time and time dot I can say sleep and I want to see for four seconds and then I will finally close it so I can say that driver dot closed or i can also say . good okay so this should run my selenium test which will set the page load time out says ten seconds go to this google.com set automation step by step in the search box and then click on the button wait for four seconds and then quit and let us try to run this I would say run and you can say there is some error okay and the problem is we do not have the groom driver exe so what I'm going to do is let us go to our browser and let us just go to selenium HQ dot over G and here let me go to downloads and here if you go down you have this third-party drivers where we have Mozilla repo driver for Firefox and we have chrome driver so let me take both of these I will take the gecko driver from here and this is the latest version so I will download the one for Windows so I will download this one and then let me also take the chrome driver and the latest version for my time is 2.0 so you can take whatever the latest version you have and again I will take the Windows version and let me also take the Internet Explorer so let me just search for various the Explorer so yes we have this here and you can take that a little bit or the 64 bit I found that 32 bit is more stable even if you are working on 64-bit operating system so I will take it here so we have got all these here let me just go and show in folder so these are the three drivers that we have got let me just unzip them okay so we have all this drivers so what I'm going to do here is I will just add another folder called library or I will just name it as I can rename it as drivers and say ok and I will add all these drivers here so I would say this is room I will just copy and paste it here chrome dot exe similarly I will add the Eco driver for Firefox I will just paste it here and similarly for IE yes so now I have got all these drivers here so here I have to tell webdriver or selenium labrys that from where you have to take the executables for this chrome driver so I will just do a right-click and say copy path and I can provide this path now here okay so I can provide this here and let me run it now run the test okay there is some issue it is saying driver dot C asset-based load time out has some issues let me just test it okay so I think it is an identity problem so what I'm going to do is I will just select everything and press control shift alt + L on my keyboard and I will say done and I think it is okay now so let me just run and test it again so this should run my test on a Chrome browser so yes the Chrome browser is opening up its adding automation step by step and it should be testing it now so yes it did not click on the submit button because it cannot find it because it is getting overlapped by this text but yes now I think it is running so what we can do here is we can add the keys libraries from selenium webdriver dot common dot keys and I will import keys from here and now instead of click I will I can say send keys keys dot enter so I am just adding this automation step by step and click on enter so let me now run this so they should open our Chrome browser and it will add the text and hit enter and yes now it is running fine and now close so we can also test it on other browsers so let me do this so let us now test with other drivers so similarly I can save driver equals web driver dot ie and here I have to cook the location for ie driver so I have to give this location I can copy path and paste it here and one thing that we can do is because this drivers folder is within our project we do not have to give the absolute path I can go to my project by just double dots and then go to drivers and have this exe and the same thing I can do with here as well so I do not have to give the entire path and now I will just comment this out and let me also comment this out so that I just want to check if this is working fine on ie I will do a right click run test and allow access for the first time it might ask you and yes it has opened our internet explorer and let us see if it goes to google.com it's taking some time so let me just close this and comment out the driver dot set which time load load time out and run it again and yes now dis running file so it is going to google.com and it is running fine now so let me just comment this out I will uncomment the chrome part and all these things I will uncomment so now we can use any of your shalini mentions you can say driver dot maximize window you can say driver dot refresh and anything so and you can test it you can just run it from here run the test it will do all these things so it has opened our Chrome browser it will go to google.com and now it should maximize the window and you can see it's maximized it's refreshed and then it will finally after four seconds it will close this window so this is running fine and her here you can say print test completed successfully ok now how do you run this from command line so in your project you will have to run this from command line as well so what you can do is you can just copy the location of this file so let me just copy this path and then you can go to your command prompt and you can go to this location so I'm going to test folder and now we can say python and the name of your python file and say enter and this should start your test so this is how you can run it from command line as well so this will now maximize it they trash it wait for 4 seconds and then finally execute it and then you can see test completed successfully so this is how you can run it so I will add step number 7 here run from IDE and then also you can run from command line so this is how you can add your project add your screen in scripts and run from ID as well as from command line let us see some useful tips so if you go to your project you can see we have added all these drivers here right and that is why we have to give this driver on exe location here as well suppose I do not add it here let me just add this to our 527 and I will just go to maybe I can go to Lib and I can add it here and you can see I have added the chromedriver here so now I have added my chromedriver in the library folder and if even if I do not give this location and try to run it let me see if I can run it now I will have to take it from here maybe I can give it inside Python 27 and try to run it and yes you can see I have not given the location of the chromedriver but it is still taking it from this folder so you can add your drivers in this folder also you can add it in I think the lips folder as well it should take it from here as well so you do not have to give the location of all your browser Exe however you want to take this project to some other location then this might read because the location may be somewhere else and it might not recognize it the browser libraries might not be there so it is a good practice to add it here within the project so you can you can just add these here and give the location here yes we have done it earlier and this should work fine okay the other useful tip is if you go to your PyCharm file and you can go to settings and you can go to build fsq deployment and click on console here if you go to console let me just say fight and control and here you can see you can see python interpreter and here you can see the python which it is using on your system so as of now we just have this particular python 27 but in case you have multiple python versions and you want it to be run with some other python version you can do this here you can add it here also if you go to your file and you go to settings and then if you go to your project so this is for selenium test my project and I go to project interpreter again here I can select the Python version per project so suppose I am having a new project that I want to use with Python 3 I can select it here and also I can see all the other libraries that are added on this project so this is how I can manage projects with multiple Python versions on the same system so this is how we get started with selenium Python in this one video we have learned all the basics to get you started I will have some more videos on some other features [Music]
Info
Channel: Automation Step by Step
Views: 290,883
Rating: 4.7221475 out of 5
Keywords: selenium python beginner tutorial, selenium python for beginners, selenium python from scratch, learn selenium python in one video, one video, learn in one video, learn selenium from scratch, python selenium beginner tutorial, python selenium tutorial for beginner, selenium for python beginner, how to run selenium python script, how to run selenium in pycharm, how to run selenium python script from command line, how to install python, python beginner tutorial, step by step
Id: FFDDN1C1MEQ
Channel Id: undefined
Length: 32min 13sec (1933 seconds)
Published: Sun Sep 17 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.