Test Automation Using Python | Selenium Webdriver Tutorial With Python | Selenium Training | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey everyone this is Neha from arica and this session is all about test automation using Python let's have a look at the agenda for the session first let's understand what the selenium and why it is required next we will see why python is preferred for automation testing once you understand this we will move further and understand the binding between selenium and Python after that we will discuss about one of the important tool to write selenium script in python that a spy Chomp and we will also understand how to locate elements in selenium and finally i will wrap up the session by automating hot star website in selenium using python so i hope you guys are clear with the agenda kindly give me a quick confirmation so that i can proceed further all right so let's get straight with a module first let's see what a selenium selenium is an open-source tool which is used for automating the tests that are carried out on web browsers wait before you get carried away let me reiterate that only testing of web applications is possible with selenium we can neither test any desktops of your application nor test any mobile application using selenium so it is an open source tool that supports the cross browsing and automates web application simple ok enough moving ahead now let's see why do we need selenium for automation testing the main reasons are the test scripts can be written in any of the programming languages like Java Python Ruby c-sharp dotnet etc and tests can also be carried out in any of these operating systems like Windows Mac Linux etc and tests can be carried out using any web browsers like Google Chrome Internet Explorer Mozilla Firefox Safari Opera etc not just that it can also be integrated with tools like test and G&J unit for managing the test cases and generating the reports and it can also be integrated with maven Jenkins and docker to achieve continuous testing so these are some of the reasons that keep selenium at the top when compared to other automation tools and that's why it is a preferred tool for testing now let's see the market trends of selenium you can see in this figure the market trends from the past ten years and you can easily make out the growth rate from 2007 till date by this you can understand the demand for selenium in the testing domain of the IT world now let's move further and understand why Python is a preferred programming language for automation testing Python is extremely simple and easy to learn at so very powerful language and it closely resembles the English language so what contributes to its simplicity Python is free and open source it is high-level interpreted and blessed with a large community and Python also has many built-in testing frameworks that covers debugging and fastest workflows there are a lot of tools and modules to make things easier such as selenium and splinter and it also supports testing with cross platform and cross browser with frameworks such as fighters and robot framework so testing is a tedious task and Python is a booster for it so every tester should definitely go for it with respect to that let's have a look at the market trends for python programming language this graph depicts the market value of Python since past 5 years and you can see the growth rate where it reads a peak maximum in the last year and recently you can see the Python counters 98 in the recent day of March 9 so this implies the market value and demand for bites and that is growing at a higher rate so let's move further and understand the binding between both of them that the selenium and Python selenium Python bindings provide a simple API to write functional tests using selenium webdriver here what you can do is you can simply write your functional test cases using selenium webdriver after that you send a request to selenium server and selenium server then runs the test cases on various browser it can be Google Chrome Internet Explorer or Mozilla Firefox so this is how it works now in order to implement the Python with selenium we first need to import the selenium webdriver so let's see how can we import selenium webdriver before that let me tell you what a selenium webdriver selenium webdriver is a web-based automation testing framework which can test the web pages that are initiated on various web browsers and various operating systems you can import the webdriver with the help of these two commands or just simply use SAS Roderick that is this one and that helps you to import all the dependencies that are required for a project now without wasting any further time let's talk about PI chomp so this is a ID where you can write the Python code or scripts in order to execute the test cases you can use any other ID for the same like you can use Thibodeau notebook shell etc over here I'm using pi Chun so this is how it looks Python is an amazing language which has various frameworks like Django flask etc you can also customize it with themes and plugins and it also lets you to enhance the productivity while coding by providing some of the features like suggestions local VCS etc now let's see what our locators in selenium the locator can be termed as an address that identifies a web element uniquely within the web page locators are the HTML properties of the web element which tells selenium about the web element that needs to perform the action on and selenium uses locators to interact with the web elements on the web page now there are diverse range of web aliments like textbox ID radio button etc and identifying these elements has been a very tricky subject and thus it requires an accurate and effective approach and thereby we can assert that more effective locator is more stable will be the automation script essentially every selenium command requires locators to find web elements thus in order to identify these elements accurately and precisely we have different types of locators like ID name link text CSS selector partial link text and XPath so let's get into the details of all these types first ID locator the best and the most popular method to identify web element is to use ID the ID of each element is alleged to be unique IDs are the safest and fastest locator option and should always be the first choice even when there are multiple choices for example it is like an employed number or account number which will be uniquely identified now let's see how to use ID locator with the help of example so first I have created a simple file in Python that is hot star and the very first step that I am going to do is I'm going to import the web driver so I am going to write it like from selenium import webdriver simple so once I input the web driver the next step is to launch the chrome driver so I'll create a new element called driver is equal to so my web driver will be Chrome and this is the path where I have saved my chrome driver okay next I will use driver dot get method and give the link of course starcom because I want to locate the elements that is present in hosta so that's a reason I'm giving this link so here I will navigate to hot star website and locate the search box first what I will do I'm inspector on this and you can see it has our ID attribute whose value a search field so I'll just copy this value now the next step is to write the script in PI Chun so I have already imported the webdriver and I've launched the link and also have registered my chrome driver so once this is done the very next step is to locate the elements and perform action on it so what I will do I'll use driver dot find element by ID and the value of ID is search field and I want to send keys as movies okay what I'm doing here is I'm finding the element by ID attribute whose value is search field and I'm sending the value to that search field as movies so I'm going to run the program let's check what will be the output so chromedriver launched Google Chrome navigated through hot Starcom and entered the value as movies in the search field so you can choose from any of these movies okay sounds much simple right so this is how you can locate the elements using ID attribute next one is name locator this is also an efficient way to locate elements with the name attribute after IDs you can give it your second preference but likewise name attributes don't have to be unique in the page with the strategy the first element with the name attribute value that is matching the location will be returned if no element has a matching name attribute then no such element exception will be raised let's see it's working it's almost same like ID attribute but the difference here is that instead of ID you have to use a name attribute so what I'll do I'll just navigate to google.com and inspect the search box and you can see it has name attribute whose value is Q so I'll just copy this open my PI charm I'll just comment this first and I will write driver dot find element by name whose value is Q dot I want to send keys as selenium and also I want to give the search as well so again that has a name attribute whose value is this so I will copy this I'll just paste it over you as it is a button I use click method because it is not a text box to send the values to it so I am just using click let's run a program and check the output so you can see it gave the search for selenium simple so this is how you can use name locator moving forward next is link text all the hyperlinks on the webpage can be identified using link text the links on the web page can be determined with the help of an anchor tag now the anchor tag is used to create the hyperlinks on the web page and the text between the opening and closing of anchor tag constitutes the link text now let's see how it works now let's switch back to Hofstra and try to locate on this particular link that does premium as you can see it consists of a link text called premium so I will write my Python script and search element by link text as Python and click on it so I'll copy this I'll open my PI charm and write drive for door find element by link text and the value is premium dot click because it is a link so let's run the program and check the output on executing the program it clicked on the premium link and gave the result so this is how it works next let's see what our CSS selectors CSS is mainly used to provide the style rules for the web pages we can use CSS for identifying one or more elements in the web page if you start using CSS selectors to identify elements you will love to speed when compared with XPath now we can also use C as a selector to make sure that the scripts run with the same speed in all the browsers so CSS selectors becomes the best possible way to locate complex elements in the web page let's locate the same search field using CSS selectors so I'll inspect on this as it has the ID attribute whose value a search field I'll just copy this and you all might know that CSS selector starts with hash so I will give hash followed by this ID attribute value as you can see it highlighted the element on writing the CSS selectors which implies it was able to locate this particular element using this particular CSS selectors now I will copy the CSS selector go to my PyCharm and right CSS selector dot send keys as sports let's check that but now so it launched all-star calm and don't sports correct so you can choose from any of these post channels your awards etc sounds simple right so that's how it works now let's move further and see how to locate elements using partial link text in some situations we may need to find links by a portion of the text in a link text element in such situations we use partial link text to locate the elements here let's try to click on this particular link itself and try to locate it so what I'll do I'll write drive word or find element by partial link text and I'll place the value as instead of giving the full value as premium I have just given the half value and I'm using click method to click on that simple let's run the program and check the output so you can see so even on using the partial value it was able to locate the element that's how partial link text locator is useful in locating the elements next let's move to the last locator that is expert so this is my favorite locator expert also called as XML path is the language to query XML documents it consists of a path expression along with some conditions now let's understand the working of XPath now here I want to perform action on this login button so what will I do I will write the expert for this as I have already added the CRO path extension I need not manually write XPath for this particular element instead I will find it using Crobat Crobat is basically a tool that is very helpful to find XPath and CSS selectors if you wish to know more about it you can check my video on new features of chrome path in our YouTube playlist now I will copy this XPath and paste this value and my script so first I will write traivor tour find element by XPath and thus I'll paste the value as it is a button I am just clicking on that ok next I want to enter the email address and password as well so in case of this it has a name attribute whose value is email so I will just copy that so I'll write driver dot find element by name and pass the value as email and I will send keys and pass the value of the email as I she at the rate at you record or cool and I'll again inspect this password field it has an ID attribute even I can use the Krupa husband so you can see the CSS selector there's a absolute expert and there's a relative expert so what I'll do I'll copy the relative XPath and I'll write find element by expert and passed value and I'll give password for that next I want to click on this button so again it has a class at this button sign but I will again copy the XPath for that that is it starts with the type whose value is submit it has a button tag and the attribute is type whose value is submit so I will copy this I will paste it over here not click ok so now when you run the program it will first click on the login icon then enter the value for your email and password after that it will click on the login button now let's run the program and check the output so when I execute the program you can see it navigated through hot Starcom clicked on login enter email address and password and click on login button clear not simple right so that's how it works so this is all about XPath and various types of locators now what is the preference for the locators so basically ID is given the first preference because it is unique if a name as well because even that is also considered as an unique locator next XPath and CSS selectors are given the second preference why because in some complex situations where ID and name are not available we have to create dynamic XPath next link text is useful only for links so I will give the third preference and partial links as my fault preference now let's do one thing let's navigate through add you like a blog page and perform some actions on it so I wish to search the blog's for Python so what I will do I'll inspect this page and I will write it using CSS selector because it has the ID attribute whose value is search input so I'll just copy that and I will write the code like this so first basically I will import the web driver I launched Google Chrome and then I will use a driver get and launch the link that is Ed Eureka blog and then using CSS selectors I'll use the search input I'll give the value of CS selector a search input and send keys as Python now let's run the program and check for the output so you can see it launched at Eureka block page and it entered the value as biotin so you can see there are so many blogs for Python there are videos there are interview questions etcetera next what I want to do is I want to click on this interview questions link so I'll just click on inspect I'll copy the link text such as interview questions now go back and write the code not click let's run the program so you can see it clicked on interview questions and you can find many of the interview questions for your preparations if you wish to now say I want to subscribe on this at Eureka channel so what will I do I'll just inspect this and I will copy the XPath for that go back to my PyCharm write it by expert dot click okay so this is a very complex XPath query so with the help of chrome part it's very simple for us to find the expert or elles manually writing such a big expert is very complicated so you can see it launched I'd you recovered site and it will now click on the subscribe button yes I want to cynics I can proceed further with my email address everything ok so that's how it works I hope you understood the concept of locators and how to automate it using selenium and Python so that's all for this session I hope you enjoyed it if you have any queries you can comment it and we will reply back to you at the earliest thank you and have a nice day I hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist and subscribe to any Rekha channel to learn more happy learning
Info
Channel: edureka!
Views: 182,814
Rating: undefined out of 5
Keywords: yt:cc=on, test automation using python, python selenium webdriver, selenium python, python selenium on windows, selenium tutorial, selenium webdriver tutorial, selenium testing, selenium ide, selenium download, python selenium no browser, test case automation in python, selenium automation testing, web ui automation testing, ui automation testing, types of automation testing, selenium certification, selenium training online, selenium training, edureka
Id: CwLrdjgsJjU
Channel Id: undefined
Length: 21min 27sec (1287 seconds)
Published: Fri Mar 15 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.