Top Selenium Interview Questions and Answers: Ace Your Tech Interview
Are you gearing up for a job interview in the tech industry? If so, you might already know how crucial it is to be well-prepared for the barrage of questions that interviewers can throw your way. In the realm of software testing and automation, knowledge of Selenium is highly sought after. To help you shine during your interview, we’ve compiled a comprehensive list of Selenium interview questions and expertly crafted answers that will give you the confidence you need to succeed. Let’s dive in!
Common Interview Questions
1.Why Selenium is Important?
Selenium is an Open Source Tool and available for testing web based , Mobile app, APIs. We can test Cross Browser ,Different Platform .There are 4 Major component of selenium – Selenium Grid, Selenium IDE, Selenium RC, Selenium WebDriver. We can Save Cost, Efforts by Using Selenium Automation Tool.
2. How you can handle drag & drop using selenium?
Using action class drag And drop method.
action.dragAndDrop(sourceEle,targetEle).build().perform();
3. How you can handle the list box?
Using Selenium Select class & its methods like selectByValue, selectByIndex, selectByID etc.
4.How can we type text a textbox element using Selenium?
sendKeys() method.WebElement(By.id("search")); searchTextBox.sendKeys("searchTerm");
5. Abstract class cannot have a constructor?
Yes
6.What is the fundamental difference between XPath and CSS selectors?
The fundamental difference between XPath and CSS selector is –
Using XPaths we can traverse up in the document i.e we can move to parent elements. Whereas using the CSS selector, we can only move downwards in the document.
7.Difference between Absolute and Relative XPath?
Absolute Path: Single Forward Slash, select the element from the root <html> and cover the whole path to the element. It is also known as complete or Full Xpath.
[Faster]Example- /html/head/body/form/table/tbody/tr/th
Relative Path: Double Forward Slash, Expression can starts in the middle of the HTML DOM structure.
[Slower]Example-//table/tbody/tr/th
8.Difference between getWindowHandle() and getWindowHandles() ?
getWindowHandle() returns the window handle id of the current browser window.
getWindowHandles() returns the window handle id of all the browser windows.
9.How do you mouse hover on any element on a web page?
Using moveToElement() of Action class
10.What is the difference between ‘/’ and ‘//’ ?
“/” refers to the immediate child element in the html tree.
“//” refers to any element in the html tree . It also represent any descendant .
11.What types of Test Case to be automated ?
Data driven test cases, higher complexity tests, smoke tests, TC with many databases updates.
12. What is used to run automation scripts on multiple system simultaneously?
Selenium Grid
13. Whar are different type of locators in Selenium ?
There are 8 types of Locators in Selenium : ID, ClassName, TagName, CssSelectors, Xpath, LinkText, Name, PartialLinkText,
14. How to capture screenshot in Selenium ?
public static void TakeSnapShot(WebDriver webdriver, String FilewithPath) //Covert webdriver object to TakeScreenShot TakeScreenShot scrshot = ((TakeScreenShot), webdriver); //Call getScreenshotAs method to create an Image File File ScrFile = scrShot.getScreenshotAs(OutputType.FILE);
15.How you will find hidden text in selenium?
Using getElementById methos we can identify element. executor.executeScript("document.getElementById('txt').value ="selenium' ");
16. How do we clear Content of Text Box in Selenium ?
WebElement el = driver.findElement(By.Id("ElementID")); el.clear();
17. How to execute java scripts function?
JavascriptExecutor js=(JavascriptExecutor) driver; String title = (String) js.executeScript("pass your java script");
18. How to automate radio button in selenium ?
WebElement el = driver.findElement(By.id("Radio Button id")); //to perform check operation el.click(); //verify to radio button is check it return true if selected else false el.isSelected();
19. How to maximize window using selenium ?
driver.manage().window().maximize();
20. How you will handle alert popup in Selenium ?
//To click 'cancel' button in alert popup driver.switch().alert().dismiss(); //To click on 'accept/ok' in alert popup driver.switch().alert().accept(); //To send data or value on alert popup driver.switch().alert().accept(); //To capture alert text in popup driver.switch().alert().sendKeys("Text");
21. What is POM?
POM is Page Object Model its an object repository design pattern in selenium webdriver. POM creates our testing code maintainable and reusable. we can use POM with page factory or without page factory.
22. What are the Page Factory Annotations ?
@FindBy @FindBys @FindAll @CacheLookUp
23. What is mean by POJO Class ?
POJO stands for Plain Old Java Object is used to describe the same thing as a “Normal Class” whereas a JavaBean follows a set of rules.
Most commonly Beans use getters and setters to protect their member variables, which are typically set to private and have a no-argument constructor.
Generate POJO Class :
RighClick-->Source-->Generate-->Getter&Setter-->SelectAll.
24. What is the difference between @FindBys and @FindAll ?
//@FindBys : When the required WebElement objects need to match all the given criteria use @FindBys annotation @FindBys( { @FindBy(className ="class1") @FindBy(className ="class2") } ) Private List<WebElement>elementWithBoth_class1ANDclass2; //@FindAll : When the required WebElement objects need to match atleast one of the given criteria use @FindAll annotation @FindAll ( { @FindBy(className ="class1") @FindBy(className ="class2") } ) Private List<WebElement>elementWithEither_class1ANDclass2;
25. What is difference between Implicit wait and Explicit wait ?
Implicit wait : sets a timeout for all successive web element searches. for the specified amount of time it will try looking for element again and again before throwing a NoSuchElementException. It waits for elements to show up .
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
Explicit Wait : It is a one-timer, used for a particular search.
WebDriverWait wait = new WebDriverWait(WebDriverRefrence , TimeOut);
26. What is Syntax of XPath ?
XPath = //tagname[@attribute= 'Value'] // ---> select current node. Tagname --->Tagname of particular node. @---> Select attribute Attribute--->attribute name of the node Value--->Value of the attribute
27. What is difference between in Assert & Verify ?
Verify : Verify command will check whether the element is on the page, if it is not then test will carry on executing, In verification, All command are going to run guaranteed even if any of test fails.
Assert : Assert allows to check whether an element is on page or not. The Test will stop on the step failed, If the asserted element is not available, In other words, Test will terminated at the point where check fails.
28. What is difference between find elements & find element ?
findElement() : It finds the first element within current page using the given ” Locating Mechanism “. It returns a single WebElement.
findElements() : Using the given ” Locating Mechanism ” it will find all Elements within Current page. It returns a List of WebElements.
29. How you will handle frame() ?
driver.switchTo().fram("Id of the element");
30. How to Right click in selenium ?
Actions actions = new Actions (driver) ; WebElement elementLocator = driver.findElement(By.Id("ID")); actions.contextClick(elementLocator).perform() ;
31. If we have findElement and there is no element & findElements there is no elements so what will return ?
findElement – it will throw an exception
findEelements– it will return 0 value
32. What is difference between Explicit wait & Fluent Wait ?
Explicit Wait : It is a one-timer, used for a particular search, it used to tell the web driver to wait for certain conditions( Expected Conditions) or maximum time exceeded before throwing an error “ElementNotVisibleException” Exception.
WebDriverWait wait = new WebDriverWait(WebDriverReference , TimeOut);
Fluent Wait : it used to define maximum time for the web driver to wait for conditions as well as the frequency with which we want to check the condition before throwing an”ElementNotVisibleException” Exception. it checks for the web element at regular intervals untill the object is found or timeout happens.
wait wait = new FluentWait(WebDriver Reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);
Conclusion
Mastering Selenium interview questions can be the key to unlocking exciting career opportunities in the tech industry. By understanding the core concepts, techniques, and best practices discussed in this article, you’ll be well-equipped to impress interviewers with your knowledge and expertise in Selenium automation testing. Remember, preparation is the cornerstone of success, so keep practicing and refining your skills. Good luck on your interview journey!
Leave a Reply