Selenium Middle interview questions and answers

75 questions for a Selenium (Middle) interview - with correct answers, explanations and links to the docs.

  1. 1.What does FluentWait add over a basic WebDriverWait?
  2. 2.How do you wait for a custom condition, e.g. a counter showing 5?
  3. 3.Why can @FindBy fields with PageFactory cause stale element errors?
  4. 4.What is a page component (or fragment) object?
  5. 5.What does a fluent page object method return after navigation?
  6. 6.Where should the constructor of a page object check that it's on the right page?
  7. 7.What is the purpose of a driver factory?
  8. 8.How do you run Selenium tests in parallel with TestNG?
  9. 9.What are the main parts of Selenium Grid 4?
  10. 10.Why are official Selenium Docker images popular for Grid?
  11. 11.What are capabilities in WebDriver?
  12. 12.What does WebDriver BiDi enable that classic WebDriver couldn't?
  13. 13.How can a Selenium 4 test fail when the page logs a JavaScript error?
  14. 14.How do you test a file download in Chrome with Selenium?
  15. 15.What does the page load strategy eager change?
  16. 16.What does ElementNotInteractableException usually mean?
  17. 17.A sticky header covers the button the test clicks. What helps?
  18. 18.How do you find a table cell next to a row label with XPath?
  19. 19.Which XPath handles a button whose id changes, like save-8842?
  20. 20.Why does HTML5 drag and drop often fail with Actions.dragAndDrop?
  21. 21.How do you take a screenshot of just one element?
  22. 22.What are soft assertions good for in UI tests?
  23. 23.Why log in through the API and inject cookies instead of using the login form in every test?
  24. 24.How do you set a value in localStorage from a test?
  25. 25.What should happen between tests that reuse the same browser?
  26. 26.How do you test an infinite-scroll list?
  27. 27.How should a test handle a custom date picker?
  28. 28.What does Select.isMultiple() tell you?
  29. 29.How do you send Ctrl+A to an input?
  30. 30.Why add Allure steps and attachments to Selenium tests?
  31. 31.What is a risk of a TestNG retry analyzer for UI tests?
  32. 32.Why prefer explicit waits for a specific state over waiting for 'page load'?
  33. 33.How do you wait until a loading spinner disappears?
  34. 34.What is the main benefit of running Grid nodes in containers?
  35. 35.What does driver.manage().timeouts().scriptTimeout(...) control?
  36. 36.How can Selenium 4 emulate a user's location?
  37. 37.What changed for capabilities when moving from Selenium 3 to 4?
  38. 38.What does Selenide's shouldHave(text("Saved")) do?
  39. 39.How do you read all rows of an HTML table into a list?
  40. 40.Why do tests sometimes pass locally but fail in headless CI?
  41. 41.What's a safe way to deal with a cookie-consent banner in tests?
  42. 42.How do you get the text of an input the user typed into?
  43. 43.What's the risk of very long implicit waits in a suite?
  44. 44.How do you test a site in a specific language with Chrome?
  45. 45.Why should page methods not return raw WebElements to tests?
  46. 46.What is a good use of the @BeforeMethod hook in TestNG UI tests?
  47. 47.Why does alwaysRun = true matter on TestNG teardown methods?
  48. 48.How do you verify a link opens in a new tab without following it?
  49. 49.What's a reasonable approach to visual checks in Selenium suites?
  50. 50.How do you handle an HTML modal dialog (not a JS alert)?
  51. 51.Why should locators avoid CSS classes generated by build tools like css-1x9k2?
  52. 52.What does running tests on several browsers in Grid at once require?
  53. 53.How do you test that a button becomes enabled after filling a form?
  54. 54.What does driver.switchTo().newWindow(WindowType.TAB) do?
  55. 55.Why may tests in Firefox behave differently from Chrome for the same locator?
  56. 56.What is a good way to make a flaky UI test deterministic?
  57. 57.How do you open a page with HTTP basic auth in Selenium 4 Chromium?
  58. 58.Why is reading the table text with one getText() and splitting it fragile?
  59. 59.What's the role of a base page class in a framework?
  60. 60.Why save page source and screenshots on every failure?
  61. 61.How do you check that a downloaded PDF has the right name?
  62. 62.What does ExpectedConditions.frameToBeAvailableAndSwitchToIt do?
  63. 63.How do you handle nested iframes?
  64. 64.Why prefer API calls for test data setup over UI steps?
  65. 65.What is the trade-off of using Cucumber on top of Selenium?
  66. 66.How do you test a tooltip that appears on hover?
  67. 67.What should happen to the driver when a test is interrupted by a timeout?
  68. 68.Why may click() on a link in a hidden menu fail on mobile widths?
  69. 69.What's a good naming practice for UI test methods?
  70. 70.What does ExpectedConditions.refreshed(...) help with?
  71. 71.Why keep the WebDriver version and the browser version in sync?
  72. 72.What is a good way to check text that loads with a delay?
  73. 73.How do you scroll to an element with the Selenium 4 Actions API?
  74. 74.Why should a UI test framework capture the browser and driver versions in reports?
  75. 75.What does getDomProperty("checked") return for a checkbox?