Hello everyone, in this video session, I am going to explain part five of selenium four that is taking screenshots of the complete webpage in Chrome browser using get screenshot has mentored. So, in Selenium four a new method has been introduced. That is, get screenshot as method. The new method known as a screenshot as method, using which we can perform two tickets, okay in this using this circuit screenshot as method, you can do two things like you can either take the screenshot of a specific UI element, okay already explained how to take the screenshot of a specific UI element like button or checkbox option or radio button using this get screenshot as method in one of the previous videos, the current video. Okay, I'm going to explain The other thing that this gets screenshot as method can do in Selenium for that is taking a screenshot of the complete webpage complete webpage full web page in Chrome browser this Okay, this will work in Chrome browser, but taking the screenshot of the complete webpage.
Okay, so let me practically demonstrate this for you. For that, let me open Eclipse ID. Here you see guys there is a Naveen project, which is already created, and it is configured with Selenium four and other stuff. Okay, so the details on how to configure this Maven project with Selenium four and other stuff are already explained as part of the first video in this Selenium four video series. You can go through that video, if you are not aware of hoping that you have created this Maven project and configure that with Selenium for another okay. Other dependencies, then come here guys and create a new class here new class and name this classes like something like demo five and select this public static Weidman and select Finish.
So, a class with inside having this main method will be created inside the main method, write the Selenium stuff like WebDriver manager, this foreman stuff case, dot setup, then driver dot WebDriver driver is equal to new chrome driver. So I have to use only chrome driver gains because this get screenshot as method will take the screenshot of the complete webpage only Chrome browser. Okay, so better create this chrome driver and import this web driver interface and chrome driver class, then maximize a browser window. It's better to maximize a browser Literally every time guys because there are like it's better to do that okay to test in Nigeria is more so that you will see less issues. Since Selenium four is still in alpha state. Two commands may not work in other and all those stuff again just avoid that.
Just go blindly go which is nice west for now and driver dot manage dot timeout dot, let's implicitly wait so that our tests will not fail. Okay, just give some 20 seconds or any seconds whatever you wish and say time unit dot seconds. This is a basic code. This will get executed even in Selenium three also. Okay, common code right. Now, what I want to do, I want to take the screenshot of this complete webpage.
This complete web page I want to take further and I have to first open this application URL. And for that, I will write driver dot gate and paste the URL here. This will open the application URL. Now I want to take the screenshot complete screen Shut off this webpage for that. What I will do here is how to cache the driver. Okay, how to Casa driver using Chrome driver, Chrome driver driver, okay, just cast it to chromedriver and then say dot get screenshot ass okay and how to type this output type or word type dot file to say okay and just remove this section which is not required and then say semicolon for the most it will return you the file guys file SRC file is equal to some source file is equal to import this file from Java and now the screenshot of the complete web page is complete web page will be taken by this get screenshot method, okay, of selenium code, and it will be stored into this SRC file.
Now, we need to copy this screenshot that got stored into this SRC file into one of the folder under this project. Okay? So for that you can create any folder anywhere in this project guys. Okay, and let's create this folder under this target folder, new folder. Okay, under target folder, we are creating another folder. Let's name this folder as screenshots folder and say finish screenshots folder got created.
Now let's copy the screenshot that got stored into this file into the screenshots folder. For that we can use file utils dot copy path, dot copy, file, okay, yes file. It's not bad, it's fine. So and make sure that if you are getting any error guys for this statement if you're getting any other error, just import this statement okay? import or.apache.comments.io dot file utils Okay, so you can also add this dependency in case the error is not getting resolved just add this common sort of common siphon IO dependency so that the error will be resolved or no I'm not getting any error in my case but in your case if you get an error just to do like that, okay, now this is a source file where the screenshot is saved by this get screenshot as method from this place we want to store in a different location that is under the screenshots folder we have to copy this SRC file to okay.
So what that say new file of so provide double quotes and this is project means dot slash, slash means this target, slash then target then since target folder is directly under this Selenium for project folder for project, so we can say dot slash target or project under the under the target folder is there, then slash, we have the screenshots folder. Let's give the screenshots folder now slash gnosis slash. Now do any name, that's okay that you want to store this, like save this file, the file name of the image that you want to save here, okay? So let's say full page. Okay full page chrome dot png, okay, now for the most on this error and say add throws declaration to resolve this error. Once the screenshot has been taken and stored into the source file, and from the source file if when we copy this image stored into the source file into this new folder location that is under target screenshots with the name full page chrome dot png after that, we can simply close it right.
Okay and save it note on it. This time, it should take the screenshot of the complete web page case. Okay, in the Chrome browser, you see the Chrome browser has been launched. It will get maximized now in a while. And once the application is open, we'll take the full screenshot and then close the browser. Now let's refresh this screenshot folder.
And observe that there is a screenshot taken here, open the screenshots, report here and as you can see, the screenshot of the complete web page has been taken here okay. So properties you can also open the screenshot in your local machine also and this is a screenshot being taken guys. The screenshot of the webpage has been taken here. So guys, this is how we can take the screenshot of the webpage using get screenshot as method in Selenium. So that's it. The next video session I am going to explain how to Take full screenshot of the page using another method known as get full page screenshot as method.
Okay is another method for using this method and this method are different ways. So get screenshot as method is different from get full page screenshot as method. Okay, this works this full full page screenshot as method works in Firefox browser. Okay, this is for Firefox browser. So in the next video session I am going to explain in detail how to use this get full page screenshot as method for taking the screenshot of the complete page in Firefox browsers. So that's it guys.
See you in the next video session. Thank you. Bye