Thumbnail for How To Explain Method Overloading With Selenium | Selenium Interview Question by Mukesh otwani

How To Explain Method Overloading With Selenium | Selenium Interview Question

Mukesh otwani

8m 34s926 words~5 min read
Auto-Generated

[0:00]Hey everyone, this is Mukesh Otwani once again from learn-automation.com. Today in this video, we are going to talk about method overloading in Selenium. So basically, if you are attending interviews for automation and if you have mentioned Selenium, then you can expect this question. The question can be explain how do you use method overloading in your framework? Or you can expect this question that explain method overloading concept via Selenium, or tell me certain scenarios where you have used method overloading in Selenium. The answer is very straightforward. I will give you three different examples, but once you go through Selenium, once you go through Selenium WebDriver basically, you will notice many places you will see method ruling concept, okay? Now, let me first show you what exactly is method overloading. So, those who are completely new to Java, then I would highly recommend you to watch the previous recordings where I explain what is overloading. Okay, so in simple terms, it's part of polymorphism. So, whenever you talk about oops concept, polymorphism is one of the most important concept. Here we have overloading and we have overriding. In this video, we are focusing on overloading, that to method overloading. In the next video, I will talk about constructor overloading. In method overloading, we will overload the method, and in the constructor, we will overload the constructor. Similarly, when it comes to overriding, we'll talk about method overriding that too in a different video, not in this video. Now, the moment you talk about overloading, in simple terms, when you see one method or constructor in multiple forms. One thing in multiple forms, which is basically polymorphism. Overloading means we are using same method multiple times with different signature, okay? So, same method or cons with different signature. So, when I say signature, it means number of arguments, then type of argument, and then order of argument. Don't worry, if you stick to this video till the end, I will explain all of this through examples with Selenium so that you can explain in interviews. So, when you see one method or constructor with different signature, signature means number of arguments, type of arguments, and order of arguments, we say as a method overloading. The question is how do you use overloading concept in Selenium or where do you use overloading with Selenium? Let me show you now. So, for this, I will create a sample class. I will say method overloading in Selenium. Now, I'm using public static void main, but you can use at the test annotation with J unit or testNG. So, in order to start, I need WebDriver. So, let me quickly start WebDriver. So, WebDriver driver equal to new ChromeDriver. First example, the moment you use switch to command. Notice here, we have frame method. So, basically, this is another interview question that we can discuss. Explain switch to command. So, we have switch to frame, switch to window, and switch to alerts. Now, notice here the frame method is coming three times, right? Switch to frame, switch to frame, switch to frame, method name is same, but if you notice, type of argument is different. First of all, number of argument is one, one, one. This one is accepting index, this one accepting string, this one accepting web element. So, number of argument one. But type of argument is different. Here it says type you have to pass as a integer index, second one says name or ID, third one says web element. Perfect example for method overloading in Selenium WebDriver.

[4:10]You can explain in a same way that whenever we switch to a frame, we have a frame method which is overloaded. Why we say overloaded? Because we have different ways to switch to a frame, either index or name and ID or using web element. Stick to this example. Now, I'm assuming if you are watching this interview series, then you must be familiar. But if you are not familiar, I would highly recommend before jumping into interview questions, go through the concept first. Second example, which you can explain is actions class. So, actions class basically in Selenium, we use whenever we have to perform advanced activities, like drag and drop, keyboard activities, mouse activities, mouse over, right? Now, if you notice here, click method. Click method is overloaded. If you notice here, click method with zero argument, click method with one argument.

[5:10]Number of arguments are different. Method is same, but arguments are different. Method overloading. Notice another example, click and hold, click and hold. Zero argument, one argument, context click, zero argument, one argument, double click, zero argument, one argument. So, method overloading again, you can explain using actions class.

[7:33]You can mention we have used Selenium WebDriver and using Java and we have seen multiple examples of method overloading in Selenium. So, while switching to frame, we have frame method. While using actions class, we have multiple methods which is overloaded. And while using JavaScript executor, we have method which is overloaded. So, depends on the argument which we pass, the respective method is getting called. Yeah, so that's all about this video.

[8:18]If you find this video helpful, then please share with your friends, colleagues. And if you're new to this channel, then don't forget to subscribe this channel. If you have any question in your mind, let me know in the comment section and I will take it in the next video. Thank you so much. Have a nice day.

Need another transcript?

Paste any YouTube URL to get a clean transcript in seconds.

Get a Transcript