Skip to main content

Selenium Interview Questions

Question Answer
What is Selenium? Selenium is a suite of tools for automating web browsers.
What are the different components of Selenium? The different components of Selenium are Selenium IDE, Selenium WebDriver, and Selenium Grid.
What is Selenium WebDriver? Selenium WebDriver is a web automation framework that allows you to write test scripts in programming languages such as Java, Python, and C#.
What are the advantages of Selenium WebDriver? The advantages of Selenium WebDriver are that it is open-source, supports multiple programming languages, and can interact with multiple browsers.
What is the difference between get() and navigate() methods in Selenium WebDriver? get() method is used to load a new web page in the current browser window, while navigate() method is used to navigate to a different web page within the current browser window.
What is the difference between findElement() and findElements() methods in Selenium WebDriver? findElement() method returns the first matching element on the page based on the specified selector, while findElements() method returns a list of all matching elements.
What is the use of sendKeys() method in Selenium WebDriver? sendKeys() method is used to simulate typing into an element, such as a text input field.
What is the use of click() method in Selenium WebDriver? click() method is used to simulate clicking on an element, such as a button or link.
What is the use of getText() method in Selenium WebDriver? getText() method is used to retrieve the visible text of an element.
What is the use of getTitle() method in Selenium WebDriver? getTitle() method is used to retrieve the title of the current web page.
What is the use of getCurrentUrl() method in Selenium WebDriver? getCurrentUrl() method is used to retrieve the current URL of the web page.
What is the use of isDisplayed() method in Selenium WebDriver? isDisplayed() method is used to determine if an element is currently being displayed on the web page.
What is the use of isEnabled() method in Selenium WebDriver? isEnabled() method is used to determine if an element is currently enabled or disabled on the web page.
What is the use of isSelected() method in Selenium WebDriver? isSelected() method is used to determine if a checkbox or radio button is currently selected or not.
What is the difference between assert and verify in Selenium WebDriver? The assert statement stops the execution of the test script if it fails, while the verify statement does not.
What is a TestNG framework? TestNG is a testing framework that is built on top of the Java programming language.
What is the use of @BeforeTest annotation in TestNG? @BeforeTest annotation is used to specify a method that will be executed before any test method in a TestNG test class.
What is the use of @DataProvider annotation in TestNG? @DataProvider annotation is used to specify a method that provides data for a test method in a TestNG test class.
What is the use of @Test(priority=1) annotation in TestNG? @Test(priority=1) annotation is used to specify the execution priority of a test method in a TestNG test class.
What is the use of @AfterTest annotation in TestNG? @AfterTest annotation is used to specify a method that will be executed after all the test methods in a TestNG test class have been run.
What is the use of @DataProvider(name="testdata") annotation in TestNG? @DataProvider(name="testdata") annotation is used to specify the name of the data provider method for a test method in a TestNG test class.
What is the difference between implicit and explicit waits in Selenium WebDriver? Implicit wait is a wait that is set for the entire session or until it is changed, while explicit wait is a wait that is applied to a specific element or condition.
What is the use of ExpectedConditions class in Selenium WebDriver? ExpectedConditions class provides a set of pre-defined conditions that can be used with explicit waits in Selenium WebDriver.
What is the use of Page Object Model (POM) in Selenium WebDriver? Page Object Model is a design pattern in Selenium WebDriver that separates the page structure from the test code and makes it easier to maintain and update test scripts.
What is the difference between findElement() and findElements() methods in Page Object Model (POM)? findElement() method returns the first matching element on the page based on the specified selector, while findElements() method returns a list of all matching elements in Page Object Model.
What is the use of @FindBy annotation in Page Object Model (POM)? @FindBy annotation is used to locate WebElements in Page Object Model using different locator strategies such as ID, name, class name, etc.
What is the difference between findElement() and findElements() methods in Selenium WebDriver? findElement() method returns the first matching element on the page based on the specified selector, while findElements() method returns a list of all matching elements.
What is the difference between close() and quit() methods in Selenium WebDriver? close() method closes the current browser window, while quit() method closes all the browser windows associated with the WebDriver instance.
What is a JavaScriptExecutor in Selenium WebDriver? JavaScriptExecutor is an interface in Selenium WebDriver that allows execution of JavaScript code in the context of the current browser window.
What is the use of windowHandles() method in Selenium WebDriver? windowHandles() method returns a set of window handles for all the browser windows opened by the WebDriver instance.
What is the use of switchTo() method in Selenium WebDriver? switchTo() method is used to switch the focus of the WebDriver instance to a different browser window, frame, or alert.
What is the use of Actions class in Selenium WebDriver? Actions class in Selenium WebDriver provides a set of methods to perform complex user interactions such as drag and drop, double-click, right-click, etc.
What is the use of Robot class in Selenium WebDriver? Robot class in Selenium WebDriver provides a way to simulate user input such as keyboard and mouse actions.
What is the use of Select class in Selenium WebDriver? Select class in Selenium WebDriver provides a set of methods to interact with dropdowns and multi-select elements.
What is the use of getCssValue() method in Selenium WebDriver? getCssValue() method returns the value of a CSS property of a WebElement in Selenium WebDriver.
What is the use of getAttribute() method in Selenium WebDriver? getAttribute() method returns the value of an attribute of a WebElement in Selenium WebDriver.
What is the use of isDisplayed() method in Selenium WebDriver? isDisplayed() method returns true if a WebElement is currently displayed on the page, false otherwise.
What is the use of isEnabled() method in Selenium WebDriver? isEnabled() method returns true if a WebElement is currently enabled on the page, false otherwise.
What is the use of isSelected() method in Selenium WebDriver? isSelected() method returns true if a WebElement is currently selected on the page, false otherwise.

Comments

Popular posts from this blog

How to integrate Autoit with selenium

For handling Dialog boxes which are not web based, Then Autoit is the best Tool to handle this These are the following code should written in Selenium Selenium Code: try { String[] commands = new String[] {}; commands = new String[] { "Path" }; // location of Autoit EXE file Runtime.getRuntime().exec(commands); } catch (IOException e) { } Autoit code: if WinWaitActive("File Upload") Then ;MsgBox(2,"window found","Found the window") WinActivate("File upload") Send("!n") Sleep(5000) Send("File path") SEND("{ENTER}") ;location of the file you want to a to the form and submit ;Send("!O") Else MsgBox(1,"TimeOut","Timed out") EndIf Here we need to create a Exe file for the Autoit script and that path should be mentioned in selenium code.

Reflection API

The Reflection API allows Java code to examine classes and objects at run time.The new reflection classes allow you to call another class's methods dynamically at run time. With the reflection classes, you can also examine an instance's fields and change the fields' contents. The Reflection API consists of the java.lang.Class class and the java.lang.reflect classes: Field, Method, Constructor, Array, and Modifier. Example program: import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; // calling method whose name we store in a variable public class ReflectionAPI { public static void main(String[] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { String x="sampleTest"; //String meth=read name from xls file Method method= ReflectionAPI.class.getMethod(x, String.class); method.invoke(method, "welcome"); System.out.

Collection API

CollectionAPI: The Java Collections API's provide Java developers with a set of classes and interfaces that makes it easier to handle collections of objects. In a sense Collection's works a bit like arrays, except their size can change dynamically, and they have more advanced behaviour than arrays. Example program: import java.util.ArrayList; import java.util.Hashtable; public class CollectionAPI { /** * @param args */ public static void main(String[] args) { int names[] = new int[5]; ArrayList list = new ArrayList (); list.add("Ramu");//0 list.add("Venu");//1 list.add("Raju");//2 System.out.println(list.size()); for(int i =0; i<=list.size(); i++) { System.out.println(list.get(i)); } // key - value // key - unique Hashtable table = new Hashtable (); table.put("name", "Hyderabad"); table.put("place", "Mumbai"); table.put("na