Actions Class In Selenium : MouseMovement || Right Click || Drag & Drop

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so yeah so today I'm going to cover all the actions methods water different things we can perform using the actions class and it's very very important for interview point of view as well as in your project also or definitely it will help you so I can give you some example like how will you do mouse-over right you have to mouse over on a specific element how will you do that you have to let's see you have to do drag and drop so how will you do drag and drop like 1 object you have to drag and drop it somewhere so drag and drop features also we can handle it by using selenium with with the help of actions class and I can give you one more example let's see a right-click sometimes we have to do right click I'll show you how to do that like this let's see this button is there and you have to right-click on it like this right so you can right-click on it and then you can select some option or something like this so how to do that so so these are the things that we can do it with the help of actions class so let me create let's start with the mouse over let me get a class and let's make last name is I would say mouse movement select the main method click on finish let me copy this VIP launched google chrome like this and I'll give you an example I'll show you first I vary exactly we can do mouse over or Mouse woman we have just a minute see I will show you one thing this is the site is available see if you see this particular site here we can do some mouse movements where so you just need to mouse over on content and then you will see articles courses and single videos so what I'm saying is you have to mouse over on content menu so this is a parent menu and these are the three sub menus are available so sometimes there are a number of options a number of links are available in the form of parent menu we will say main menu okay this is also called menu and submenu health handling in selenium so how we do that so so you can see there's some menu right so you just need to mouse over and submenus will be displayed so if you come on this page and if you directly try to click on courses or articles because you won't be able to do that because it's not visible on the page right so you won't be able to do that because it's not visible on the page so obviously it will give you element not found exception or something like this so in that case what we have to do that first we have to make it visible and then articles courses or single videos we have to click on it so how to do that so first we have to mouse over on content once it is visible then click on it if you directly come on this page and without mouse over right now articles or courses or these sub menus are not visible right now if you try to click on it and we'll give you an exception so you have to make it visible first and then click on it okay so how we do that driver dot we will launch the URL and the URL is this okay what we have to do we have to create the object of actions class equal to new action this actions class is already available in selenium actions I'm talking about not action actions and this is the reference name you can give any name and this actions is available you need selenium to PHP be imported and inside these actions you have to pass your above trying for instance that okay they will drive on reference so my webdriver reference is this so what is your webdriver my driver is this private ok after that what we have to do we have this method action dot move to element method is where the action not move to element on which animal you want to move to which element you want to move so I want to move let's see first and coming on this page I want to move on this particular animal on content element right so I will spec this one tenth element this means we have moved it so as inspect this point in there and I can see that okay this is the a and I can see that class is equal to monument so I can use by dot class name smooth element on which element is engine driver don't find it amended by dot class name that lets my class name is this manually okay so move on this part of the element and now with actions as days we have to use two methods after action dot move to element dot and don't perform this is compulsory to use build and perform so don't build it and not perform what exactly does dog build method will return one action class object and then dot perform method it's a void method what exactly it will do it will it will tell selenium to perform this action I mean to build it this particular action on the business of this private or find element by the trust name and then dot perform method will perform this action ok this is a description it's return ends inside the selenium Java doc that a build method it will build the entire you know on the basis of the web element ok from move element and then perform it so whenever always remember whenever he is using actions classes we have to use at the end to be able to use dot build not perform okay now what exactly it will do it will just move on that particular element so it will just move on that particular element and let's see it is moving or not so till here it's working or not let's run it so it's launching the browser and click the URL see it is moving over there right it's moving on content now the articles courses single video is these three things are available visible and then I'll click on it ok so how to click on it so simple and we will do one thing we will wait for 33 seconds you give a pause for three seconds and let me add throws declaration and now we have to click on it so let's say I want to click on articles so what I will do that inspect articles so you will see that articles are available over here this is the ailing articles is available inside you and Li Na okay and ul is having this class name is equal to submenu so while you create my own XPath like this don't worry that how it's accumulating clicks but the try but not find any way by dot exe XPath my XPath is like this you will wear at the rate class is equal to plus is equal to submenu right and inside that we have an Li and then we have one na okay a having articles let's check this expose character on don't worry about this expose on how exactly I'm grading you tell you see sex part is correct and not click so what exactly I'm doing over here that I can use by adult link text also directly but sometimes by adopting text doesn't work so what are we gonna do that I'm creating my own XPath like this then I can see that this articles are with the articles is available inside this UN having this parent tag you will class equal to submenu under that we have one li and then we have this a link and a is having this text that is articles right so I can create simple you will AB grade class equal to submenu double slash ni is the giant egg double slash a is the child of el ni having text is equal to articles like this so let's see it is clicking on it on which launches around you it should bounce over and then after three seconds it should click on articles see it is keep you long articles perfect right so this is how we do simple mouse movement and then all the menu and submenu you can handle it like this there are so many examples there are so many applications are there where or menu and some menus are available you can take any example if you take some other example let's see we can take some SpiceJet dot form we will take some other example it's make my trip calm so you can see these submenus are available these are menus but there are no supplements see here some menu if you mouse over on more these are the sub menus are available so you can perform this under action also you write I want to click on blog or DS or international holidays something like this probably click on it first time you are not able to see that you have to bounce over and then only it will be visible right let's see some other example clear trip.com do we have any submenu no here we don't have any submenu may be some other example the three skies mmm you know also they have removed actually earlier they were having these some done anyways normally so nice they might think what I'm trying to say is that if any menu in sub menus are available easily you can click on it ok so this is the example that I have taken that it's very famous like the scenario you have to click on menu in submenu and at a time of interview also they will ask how will you handle menu and submit so this is called menu and these are sub menus so first you have to make it visible by using action dot move element simple by Road class name build it and perform it and then number of events will be visible you just need to click on it that's it ok so this is how we do bounce folder now even you can be now let's move to the drag and drop feature this is very important feature for into the boundary in use case I mean in actual work hardly you will see drag-and-drop feature okay in my career I haven't seen any feature or any scenario based on drag-and-drop in my application hardly you will see you dragons wrong okay concept but it's important for interview point of view and if you are using in your application dragon process there that you can use and if it is not applicable for you know all the dragons Rock each of them if you are dragging from your laptop you from see trying to some other side you are trying some file or something like that it won't work in that way so drag and drop it's only only available for web elements if we want to drag one element okay from one position to another position that's it so how do we got it so I have a new I have one it's really difficult to find good examples for drag and drop so let's see this is the thing you can see this side so there are two objects are available this is a target and this is wrong right so what exactly I mean dragged me to my target so this is source and this is target so what I have to do I could drag it and I could drop it over like this right maybe some file is available over here or maybe something or image is there so you have to drag and drop sometimes right so ugly you will see such kind of example but you simple what you have to do you're just shoot this drag hold it and drop it over that's it so how to do that so this is example but in selenium simple I'll launch the URL my URL is this right but in this petition is facially for this webpage what is a problem here guys I wants a problem but one more component is available can you see this box this this square box right this is a frame actually so if you right click on it you will see view frame source it means there is a frame in the application so what we have to do if you interact with these two elements you have to jump on this particular frame so you have to stretch on the frame of a spin so there are three layers three layers means first layer is browser right so that always remember there are three layers in any particular application so on any particular web page it may be two layers also it will be three layers also so what do you mean by three lives so this is a browser this is the browser to entire thing is browser we're talking would thoughts from browser this is a page right this is a page from browser to pay this is a frame this is the frame so there are three layers this is then we have webpage and then we have frame now on this particular browser page is available on this page B M number of maybe links are there buttons are there text fields are there images are they here right checkboxes are there all these things are available only on this particular page on the same page we have one frame is also available this is part of frame a frame is nothing at just a small section okay a small section is available where number of other elements web elements are also available let's see some buttons are available checkboxes are available or something is available on this frame as well so where vellum ends okay web elements can be available on the page as well as well as on the frame on the browser we don't have any browser we have this thing we have back button we have forward button we have refresh we have URL address bar right bookmarks history on menu items are available for the browser though these things we cannot automate we can automate only no ill these web elements now on this particular browser we have one page lets you google.com page or facebook.com or whatever so this is a page let see jquery.com properly so we have to we have to come on this particular page by hitting the URL so this page is available way we can see this demos downloads I gave here documentation theme is available development all these links many links and let everything settle right now we have a after page we have this frame is available so this is the three are you know I would say three hierarchy based page browser page in same so how you get to know but it's not compulsory that frame is available for all the application in 90% cases you won't find frames and according to w3c standard according to w3c standards if you are application is having if your application is having any same this is not up to that one so w3c does not recommend a frame in your application but some developers they use frame devoid of the first some developers they don't follow w3c some developers they create multiple frames or maybe some old application is there in the market in your project and they are using frames or something like this so in that case you have to switch you have to switch on that particular frame so for these andaman easily you can do the tripod or find element biotechs path and everything even do that but what about these elements same thing you have to use driver would find element biotechs but but you have to switch from page to frame and then perform some action right so this is a concept of frame i hope it's here so how will you get to know that okay there is a frame there is a frame because simple right click on it and you will see view frame source frame is already if you see some other side lets you on this side if you right-click you don't see any view frame source it means frame is not available on this particular page but here you right click you will see new frame source is available it means frame is underneath so what we had to do we have to interact with these two elements obviously so what we have to do we have to switch from page to frame so after driver or to get this particular URL right this is a URL it will open the page and then I have to switch so try about dot switch to dot frame method is there and just pass the index index means on which frame you want to do that in just a minute base sorry guys so what we have to do that we have to switch on this particular thing and I see that okay there is only one frame to just pass the index index is zero this is my default pass index zero it means now this particular line will open the browser this is a first layer the second layer is dry but get that is your page layer and the third layer is that switch on that frame so now the Condor is available on this particular frame right if you want to handle these elements no need to switch on the frames okay but if you want to interact with these two elements I can see if you see over here here you don't see any view frame source you can see the frames only here so this particular section is the frame right so how to do that so we have switched on this particular same now the control is available over here now I want to do drag and drop so let's do it driver so what we have to do first I will create two web animals okay my web element stores element is equal to this is a level image so I will inspect this you can see D by D equal to Dragutin so i geuss ID driver dot find anybody buy it on ID ID estes okay I'm not performing any action simple create these elements and web element is available in selenium so that's import same thing for you can give any name source element or target element over dot find elements above ie D and ID of disagree so I D is equal to a tropical okay good now I have these two elements available with me I created the web element for these two ways now I have to drag this element source to target so how we do that with the help of actions class so simple actions and fast Matranga so first I'll create object of actions class and import these actions fine and then with the help of there is now remember if okay see you carefully action dot so how to do it manually first so if you really want to drag and drop you have to drag it and drop it but step by step what we have to do first we have to click on it and then hold it but first we have to move click and hold and then drop okay move to element on the spittle element and then drop it like this release it I'll repeat move to elevate click and hold and then release right so what we have to do we have this method action dot move element I'll show you just a note well actually not what move value in this menu click and hold okay which element the source element click and hold the source and winter dot on which element you want to move I'm going to move to my target element move to target a little and then after that what you want to do after that I want to this simple release it what release should action dot click and hold the source element and then move to this particularly when and then release it and then dot to build and perform the business of action class not build and the Sun so again and manually also how we do that click and hold moves to an element on this dropped and then release it same thing action dot click and hold the source element move to element to the specular target element dot only start build and go for that's it and let's see it is for see it is drag-and-drop it is dragging and dropping us so this is how we do drag and drop okay so there is a sequence sometimes we write inside the code we write like this action dot click and hold dot move to element dot if you ever use it dot build and not perform so in your in your company in your frame of making you will see this these four five lines so just assume that okay this they are using okay actions classes for drag and drop so click and hold move to element release it build it and before simply we have to remember the sequence and the matter and they will ask you a time of interview how will you drag it how you do it a rag and drop so this is the sequence we have to remember this and always build and perform because we are using actions okay okay so one more thing is available that how to do double flip right or will you perform the double clicked and or maybe generally I would say right click a key one double play actually right click so you just give you right click and then okay this menu will be displayed like this sometimes it happens that okay on your application you have to do right click or that's very there but you have to do that so how do you do that so for right click also ways you have to use your own actions classes so how to do that simple I'll show you even launched Google Chrome base will be on you yeah hey Naveen okay so I launched this UI driver dot get right and after this what we have to do let's maximize a browser as well manage dot dot maximize just it's okay if you don't maximize it on so that's fine and then I will create the actions class okay after that what we have to do now I have to right-click on it so I'll inspect this valium dip so you will see that just a minute you can see that span class equal to context menu one so I can use is I you can use this context menu one this particular class okay so I'll be using first I'll create the development for that this is a button right click button X is y is equal to use CSS selector in that case if I ever dot find element by a dot because X bar will be difficult and nothing is available that ID and the name nothing is available so I can use this class or many by door translate but the problem here is the class name is also available like this context menu one space BT and space BTW in neutral something like this so better to use by dot CSS selector I'll show you how to do that so by a dot CSS selector and I know that there is a class so just use dot because if there is a class use dot if there is a ID use hash okay so class is available and what is the initial name of the class the initial name of the class is context menu one so simple right by dot selector dot to simplify the class then foundation a new one that's it okay so this is how you can create a simple web element with the help of CSS selector I will repeat let me import this okay so driver dot find element by dot CSS selector I am using CSS selector because I cannot use expert there is no ID there is no name there is no text nothing simple I'll be using biot CSS selector and I see that the class is equal to one touch menu one space BTW in a space BTW neutral if you're using bio dot class name you insane I mean we can use by our class move also yes we can use that but it won't work why because if you take this entire class name at one point because there is a lot of spaces are available okay so by in our class thing won't work in that came to us if the space is available inside the class name it won't work so what we have to do you have to use like this by a dot C is a selector dot now to write dot and one touch menu one the initial name of the class this is actual name of the class actually context you live one okay so I have created this particular web element now now what we have to do that we have one method inside the action class action dot by using this action action dot context click organize context click on which element you want to do the context click so I want to do the context click on this particular and even right-click web element again dog build and perform dot del dot or form so simple action dot context like a right-click dot build and dot perform so contact click is the method there is no right wing or something like this so simple let's run it and we'll see it is working one of them see it is actually right-clicking on on this particular button so so far it is working now let's say I want to select any specific that you want to send a copy or something like this and that is how to do that so right click is perfectly working so what I have to do yes simple right click on it and let's yes for this copy our inspector so you will see that this Li under this you will write this box is represented by ul and then we have Li number one for cut for coffee for paste or delete and for quit so let's see this is for Li what I want to do that ok so we will take this context menu item right and we will take this context menu I can copy okay this particular CSS selector we will use why I am using this because this is common context menu item is common for all context menu icon is common for all but context menu I can copy is not common so this is for edit this is for cut this is for copy paste delete and quit right so better I'll use this context menu I can copy and then and create the web element for that X C for copy the copy is equal to me driver dot find element by author C is a selector dot this so I can use any of them because there are three classes things so what is the purpose of this class is equal to see if you see any particular class context menu item this is the first class this is a second class and this is a third class so first and second class both are same for all the engine so obviously it won't work because it will be duplicate and image in that case so context menu I can copy and be using and then what am going to do the are two simple get the text of this particular thing so simple what I'm gonna do that simple copy dot get text get the text of that particular okay we have any multi so and then it will store somewhere and some spring let you scream poppy X is equal to this and then we will print on the control let's see system dot of enemy of e-text and let's see it is working or not you can see it is hey you can same thing you can do copy dot click on c4 after clicking on copy it is showing this pop-up let's see I'll do get the text and then copy dot click also we will perform and then the moment right-click click on copy and then this pop-up should come so you might see it is working or not see it's clicking on copy and then this pop-up is coming maybe in your application pop-up won't come in your application it will be simple just copy it and then paste it something like that so you can do like that also so this is how we do right click ok by using this context make it so simple create the element and then right click on it and then after right-click whatever you want to do you want to get the text or you want to click on some some other items so parents also like these are called right-click items by click menu items you want to get the text you want to click on it whatever actually want to perform you can do that simple but again you have to make it visible then only you can do that it is how to make it busy but you have to right-click on it so how to right-click how will to right-click you have to do simple context click you have to use and you have to create a web element for that and then don't build on perform simple that's it so this is a purpose of actions classes
Info
Channel: Naveen AutomationLabs
Views: 40,899
Rating: undefined out of 5
Keywords: Actions Class In Selenium, MouseMovement, Right Click in Selenium, Frame in Selenium, Drag and Drop in Selenium, Context Click in Selenium, Naveen AutomationLabs, Selenium Interview Questions
Id: wq2BfYTWdmg
Channel Id: undefined
Length: 39min 32sec (2372 seconds)
Published: Sun Jul 15 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.