0% found this document useful (0 votes)
18 views7 pages

selenium automation question

Test

Uploaded by

rahchalpune2019
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
18 views7 pages

selenium automation question

Test

Uploaded by

rahchalpune2019
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

Here’s a curated list of 50 Selenium automation interview questions for candidates with 3-4 years of

experience, including questions about automation frameworks. I'll then generate a PDF for you.

1. What is Selenium?

Answer: Selenium is a portable framework for automating web applications for testing purposes. It
provides a playback tool for authoring functional tests without the need to learn a test scripting
language.

2. What are the Selenium components?

Answer:Selenium IDE (Integrated Development Environment)Selenium RC (Remote Control) -


deprecatedSelenium WebDriverSelenium Grid

3. What are the limitations of Selenium?

Answer: Selenium supports only web-based applications, it cannot handle captcha, barcode readers, or
dynamic web content effectively, and it lacks built-in reporting features.

4. What are the types of waits available in Selenium WebDriver?

Answer:Implicit WaitExplicit WaitFluent Wait

5. What is an Automation Framework?

Answer: It is a set of guidelines like coding standards, test-data handling, object repository management,
etc., which when followed produce beneficial results such as increased code reusability, higher
portability, and reduced script maintenance costs.

6. Can you name a few Automation Testing Frameworks in Selenium?

Answer:Data-Driven FrameworkKeyword-Driven FrameworkHybrid Testing FrameworkPage Object


Model (POM)Behavior-Driven Development (BDD) using Cucumber

7. What is Page Object Model (POM) and its advantages?

Answer: Page Object Model is a design pattern that creates an object repository for web UI elements.
The advantages include code reusability, readability, and maintainability.

8. How do you implement Page Factory in Selenium?

Answer: Page Factory is a class provided by Selenium WebDriver to support Page Object Design patterns,
and it helps in initializing the web elements declared in the Page Object classes using the @FindBy
annotation.

java

Copy code

@FindBy(id = "username")

WebElement username;
@FindBy(id = "password")

WebElement password;

9. What is the difference between driver.get() and driver.navigate().to()?

Answer:

driver.get(): It loads a new web page and waits for the page to load before proceeding.

driver.navigate().to(): It loads a new web page but does not wait for the page to load.

10. What are the different types of locators in Selenium?

Answer:IDNameClass NameTag NameLink TextPartial Link TextXPathCSS Selector

11. How do you handle a dropdown in Selenium?

Answer: You can use the Select class to handle dropdowns in Selenium WebDriver.

java

Copy code

Select select = new Select(driver.findElement(By.id("dropdown")));

select.selectByVisibleText("Option 1");

12. How do you handle alerts and pop-ups in Selenium?

Answer:

To handle alerts: Alert alert = driver.switchTo().alert();

To handle pop-ups, you may need to use a WindowHandle or handle elements using an iframe.

13. How would you switch between multiple browser windows?

Answer: Using driver.getWindowHandles() which returns a set of window handles and


driver.switchTo().window(handle) to switch between them.

14. What is XPath?

Answer: XPath (XML Path Language) is used to find the location of elements on a web page using XML
path expressions.

15. Explain the difference between Absolute XPath and Relative XPath.

Answer:

Absolute XPath: Starts from the root node (/html/body/...).

Relative XPath: Starts from any node in between (//div[@id='example']).

16. What is the use of JavascriptExecutor in Selenium?


Answer: It is used to execute JavaScript code within the WebDriver. It can be used to perform operations
like scrolling, clicking hidden elements, and entering text.

java

Copy code

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("window.scrollBy(0,1000)");

17. How do you handle dynamic web elements in Selenium?

Answer: By using dynamic XPath expressions or waiting mechanisms like Explicit or Fluent Waits.

18. How do you handle frames in Selenium WebDriver?

Answer: You can switch to frames using driver.switchTo().frame() with the frame's index, name, or
WebElement.

19. How do you capture screenshots in Selenium WebDriver?

Answer:

java

Copy code

TakesScreenshot ts = (TakesScreenshot)driver;

File src = ts.getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(src, new File("screenshot.png"));

20. What are TestNG and its annotations?

Answer: TestNG is a testing framework inspired by JUnit. It offers annotations like:

@Test

@BeforeSuite

@AfterSuite

@BeforeTest

@AfterTest

@BeforeMethod

@AfterMethod

21. What is the use of the TestNG XML file?

Answer: It is used to configure the execution of test classes and methods, include or exclude tests,
parameterize tests, and define test suites.
22. What is Parallel Testing in TestNG?

Answer: Parallel testing allows the execution of multiple tests simultaneously on different machines or
browsers to reduce the overall test execution time.

23. How do you manage test data in automation frameworks?

Answer: Test data is typically managed using Excel sheets, databases, property files, or JSON/XML files.

24. How do you handle SSL certificates in Selenium WebDriver?

Answer: SSL certificate errors can be handled by configuring the desired capabilities in the WebDriver.

java

Copy code

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

25. How do you handle file uploads in Selenium?

Answer: You can send the file path to an input element using sendKeys() for file uploads.

java

Copy code

driver.findElement(By.id("upload")).sendKeys("path_to_file");

26. How would you handle exceptions in Selenium WebDriver?

Answer: By using try-catch blocks and handling exceptions such as NoSuchElementException,


TimeoutException, etc.

27. Explain a typical framework structure for Selenium?

Answer:

Test Scripts: Contains test cases.

Object Repository: Contains locators.

Utility Functions: Reusable methods.

Test Data: External test data like Excel sheets.

Configuration: Property files for configuration settings.

Reporting: Generating reports using frameworks like TestNG or Extent Reports.

28. How do you create and use an object repository in Selenium?

Answer: An object repository is a centralized storage for storing all web elements’ locators, typically
using a properties file or a JSON/XML file.
29. What is the difference between findElement() and findElements()?

Answer:

findElement(): Returns the first matching element.

findElements(): Returns a list of all matching elements.

30. What is Fluent Wait in Selenium?

Answer: Fluent Wait defines the maximum time for WebDriver to wait for a condition while ignoring
exceptions during polling.

31. What is the purpose of DesiredCapabilities in Selenium?

Answer: DesiredCapabilities helps in setting up browser-specific settings such as enabling JavaScript,


accepting SSL certificates, setting proxies, etc.

32. What is the difference between BDD (Cucumber) and TDD?

Answer:

BDD (Behavior Driven Development): Focuses on the behavior of an application for end-users using
Cucumber or Gherkin language.

TDD (Test Driven Development): Focuses on writing test cases first and then writing code to pass the
tests.

33. What is the role of Gherkin language in Cucumber?

Answer: Gherkin is a domain-specific language that enables the writing of test cases in plain English
which Cucumber can interpret.

34. Explain how to write a simple Cucumber test scenario.

Answer:

gherkin

Copy code

Feature: Login feature

Scenario: Successful login

Given the user is on the login page

When the user enters valid credentials

Then the user should be redirected to the homepage

35. What is Cross Browser Testing?

Answer: Cross Browser Testing is the practice of testing a web application across multiple browsers to
ensure compatibility.
36. How can you perform cross-browser testing in Selenium WebDriver?

Answer: By using WebDriver with different browser drivers (like ChromeDriver, GeckoDriver) and running
the tests on multiple browsers.

37. How do you achieve headless browser testing in Selenium?

Answer: By using headless browsers such as Chrome Headless or Firefox Headless.

java

Copy code

ChromeOptions options = new ChromeOptions();

options.addArguments("--headless");

WebDriver driver = new ChromeDriver(options);

38. How do you test a mobile web application using Selenium?

Answer: By using Appium along with Selenium WebDriver, which allows testing on mobile devices.

39. What is Selenium Grid and why is it used?

Answer: Selenium Grid allows the execution of parallel tests across different machines and browsers.

40. How do you perform data-driven testing using TestNG?

Answer: Using the @DataProvider annotation to supply test data from external sources like Excel or
databases.

41. How do you handle browser cookies in Selenium?

Answer:

java

Copy code

// Add a cookieCookie cookie = new Cookie("key", "value");

driver.manage().addCookie(cookie);

// Get cookies

Set<Cookie> cookies = driver.manage().getCookies();

42. How can you verify the presence of text on a web page using Selenium?

Answer: Using assertions to check the presence of text:

java
Copy code

Assert.assertTrue(driver.getPageSource().contains("Expected Text"));

43. What is the difference between quit() and close() in Selenium?

Answer:

quit(): Closes all browser windows and ends the WebDriver session.

close(): Closes the current browser window.

44. What are some common exceptions in Selenium WebDriver?

Answer:NoSuchElementExceptionStaleElementReferenceExceptionTimeoutExceptionElementNotVisibleE
xceptionWebDriverException

45. How would you handle AJAX-based applications in Selenium?

Answer: By using explicit waits to wait for AJAX elements to load fully before interacting with them.

46. How do you perform logging in your automation scripts?

Answer: By using logging frameworks like Log4j or built-in logging in programming languages like Java.

47. How do you configure WebDriver in Jenkins for continuous integration?

Answer: By installing Jenkins, configuring the Selenium WebDriver on the Jenkins machine, setting up
project builds using Git/SVN, and triggering tests on each code push.

48. How do you generate HTML reports in Selenium?

Answer: By using frameworks like TestNG or Extent Reports, which provide detailed HTML reports of
ttest executions.

49. How would you handle timeouts in WebDriver?

Answer: By setting implicit or explicit waits. Implicit waits apply globally, while explicit waits are used for
specific conditions.

50. How do you ensure that tests are independent in Selenium?

Answer: By ensuring that each test starts with a clean slate and does not depend on the execution or
output of other tests.

You might also like