These Deloitte automation testing interview questions reflect what candidates commonly report for QA automation roles: a practical locator exercise on a live-looking e-commerce page, XPath versus CSS selectors, dynamic elements, Cucumber feature-file design and how object-oriented concepts show up in a BDD framework. Answers are written to be spoken, with the follow-up questions interviewers tend to ask.
Locators and XPath
1. Open an e-commerce site and write the XPath for the search box.
Inspect the element in DevTools, look for a unique and stable attribute, and prefer it in this order: id, name, a dedicated test attribute, then placeholder or aria-label. For a search input with a unique id:
//input[@id='searchBox'] (best: unique id)
//input[@name='q'] (name)
//input[@placeholder='Search for products'] (placeholder)
//input[contains(@id,'search')] (partial match for changing ids)
//form[@role='search']//input[@type='text'] (anchor on a stable parent)Then verify it matches exactly one element with Ctrl+F in the Elements panel (1 of 1). Practise on automation practice sites rather than live retail sites.
2. Which locators do you use in your project, and which do you avoid?
id and name first, CSS selectors for most other elements, and relative XPath when I need text or to move to a parent or sibling. I avoid absolute XPath (breaks with any layout change), auto-generated ids and classes that look like css-1x2y3z, and index-based locators unless the order is guaranteed.
3. XPath vs CSS selector: which is better and which is faster?
CSS selectors are shorter and readable for id, class and attribute matches; XPath can match visible text and move up to parents or across siblings, which CSS can't. Speed differences are negligible in modern browsers, so choose for stability and readability. Follow-up: CSS can't select a parent from a child in Selenium; XPath can with .. or ancestor::.
4. Have you written advanced CSS selectors?
Yes: attribute prefix and suffix matches (input[id^='user'], a[href$='.pdf']), contains ([class*='btn-primary']), structural pseudo-classes (li:nth-child(3), tr:first-child) and combinators (form > button, label + input).
5. What are the types of XPath, and the difference between text() and contains()?
Absolute XPath starts from the root (/html/body/…) and breaks easily; relative XPath starts with // and anchors on meaningful attributes, so it's the one to use. text()='Login' requires an exact text match; contains(text(),'Log') matches part of the text, useful when text has extra spaces or dynamic parts.
6. How do you handle dynamic elements?
Anchor on the stable part of an attribute (contains, starts-with), use nearby stable elements and XPath axes, wait for the element to be ready with an explicit wait, and re-find elements after the page re-renders. The long-term fix is asking developers for stable test ids. More in handling dynamic locators.
Cucumber and BDD
7. Background vs Scenario Outline in Cucumber?
Background holds steps that run before every scenario in a feature file, such as logging in. Scenario Outline runs the same scenario once per row of an Examples table, for data-driven tests. They can be used together: the Background runs before each example row.
Feature: Search
Background:
Given the user is logged in
Scenario Outline: Search returns results
When the user searches for "<term>"
Then at least <count> results are shown
Examples:
| term | count |
| laptop | 5 |
| monitor | 3 |
8. What happens if a Background step fails?
The scenario it ran for fails and its remaining steps are skipped; with a Scenario Outline, each example row is reported separately. A feature file can have only one Background, and it should stay short and only contain steps every scenario truly needs.
9. Have you used OOP concepts in your Cucumber framework?
Yes. Encapsulation: page objects keep locators private and expose actions. Inheritance: pages extend a BasePage with shared waits and helpers. Abstraction: step definitions call business methods like loginPage.loginAs(user) without knowing the locators. Polymorphism: the same steps run on Chrome or Firefox through the WebDriver interface. State is shared between step classes through a context object injected with PicoContainer.
How to Prepare
- Practise writing locators live on a demo e-commerce site, explaining each choice out loud.
- Be ready to write a small feature file with a Background and a Scenario Outline.
- Revise Cucumber questions for 3 years of experience and locators in Selenium.
FAQs
What does Deloitte ask in automation testing interviews?
Commonly a live locator exercise, XPath and CSS selector questions, handling dynamic elements, Cucumber feature-file design and how your framework uses OOP, along with project and behavioural questions.