QA Interview Hub · Knowledge base · Quizzes · Українська

All topics

Selenium + Java interview questions

40 questions on Selenium + Java, from the basics to the hard ones. Answers and explanations are in the quiz and the knowledge base.

By level: Junior QA interview questions · Middle QA interview questions · Senior QA interview questions

WebDriver: architecture and drivers

  1. What is Selenium WebDriver? Junior
  2. What role does chromedriver play when a test runs? Junior
  3. What is the difference between driver.close() and driver.quit()? Junior
  4. A test fails with SessionNotCreatedException: "This version of ChromeDriver only supports Chrome version N". The project uses a current Selenium 4, yet the code has System.setProperty("webdriver.chrome.driver", ...). What most likely needs to be done? Middle
  5. What is the right way to pass browser settings (headless, window size) in Selenium 4? Middle
  6. A CI runner without internet access fails on new ChromeDriver(). What should be done? Middle
  7. driver.get() hangs on a page where a third-party widget loads forever, although the needed button is already there. What fits? Middle
  8. Why can classic WebDriver not simply "subscribe" to browser console errors while BiDi can? Senior

Take the quiz for this chapter · Read the explanation in the knowledge base

Locators and waits

  1. Developers added data-testid="pay" to a button. Which locator is the most stable? Junior
  2. What happens if you call driver.findElements(By.id("error")) and there is no such element on the page? Junior
  3. When is XPath a better choice than a CSS selector? Junior
  4. How does an explicit wait differ from an implicit wait? Junior
  5. Why does the Selenium documentation advise against mixing implicit and explicit waits? Middle
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    new WebDriverWait(driver, Duration.ofSeconds(15))
        .until(ExpectedConditions.visibilityOfElementLocated(By.id("result")));
  6. After a list refresh, a click on a previously found element throws StaleElementReferenceException. What does it mean and what to do? Middle
  7. What does the near relative locator mean in Selenium 4? Middle
    WebElement label = driver.findElement(
        RelativeLocator.with(By.tagName("span")).near(By.id("price")));
  8. Clicking "Pay" sometimes throws ElementClickInterceptedException: a spinner briefly appears over the button. What is the most correct fix? Middle

Take the quiz for this chapter · Read the explanation in the knowledge base

Page Object

  1. What is the main benefit of Page Object? Junior
  2. Where do Selenium recommendations place assertions? Junior
  3. Following the Selenium recommendations, what does a Page Object method return when another page opens after it? Middle
    public ??? loginAs(String user, String pass) {
        // fill the form, click submit
    }
  4. Why do teams move away from PageFactory with @FindBy? Middle
  5. Why extract a site header or a table into a separate component in Page Object? Middle
  6. A Page Object keeps in a field a WebElement found in the constructor. What is the risk? Middle
  7. BasePage declares a static WebDriver driver and the tests run in parallel. What goes wrong? Senior

Take the quiz for this chapter · Read the explanation in the knowledge base

Framework and runs

  1. What is the JUnit 5 equivalent of the TestNG annotation @BeforeMethod? Junior
  2. How do you run one test with a set of inputs in JUnit 5, like @DataProvider in TestNG? Middle
  3. How do you enable parallel test execution in JUnit 5? Middle
  4. The class runs from a testng.xml with parallel="methods" thread-count="4". What is most likely to happen? Middle
    public class CartTest {
        private WebDriver driver;
    
        @BeforeMethod
        public void setUp() {
            driver = new ChromeDriver();
        }
    
        @Test
        public void addsItem() { driver.get(CART_URL); /* ... */ }
    
        @Test
        public void removesItem() { driver.get(CART_URL); /* ... */ }
    
        @AfterMethod
        public void tearDown() {
            driver.quit();
        }
    }
  5. Which deployment modes does Selenium Grid 4 have? Middle
  6. A selenium/standalone-chrome container crashes on heavy pages. What should be checked first? Middle
    docker run -d -p 4444:4444 selenium/standalone-chrome
  7. All Grid 4 slots are busy and new tests are left without a session. Which part of Grid holds them until a slot frees up? Senior
  8. The team added an automatic retry of failed tests and the suite turned green. Which approach is right? Senior

Take the quiz for this chapter · Read the explanation in the knowledge base

Stability and debugging

  1. What is Allure used for in a Selenium project? Middle
  2. Why is Thread.sleep(5000) after a click a bad waiting practice? Junior
  3. What is the most convenient way to save a screenshot only for failed tests in JUnit 5? Middle
  4. A test passes alone but fails within the full suite. What should be checked first? Middle
  5. How do you hover over a menu item in Selenium so a submenu opens? Middle
  6. How do you upload a file into a form with <input type="file">? Middle
  7. After a click a new tab opened, but findElement searches on the old one. What needs to be done? Middle
  8. The button is visible on the page, but findElement throws NoSuchElementException. It is inside an iframe. What to do? Middle
  9. A new project must catch console errors and network requests in Chrome and Firefox. What to choose? Senior

Take the quiz for this chapter · Read the explanation in the knowledge base