Selenium interview questions
Selenium questions interviewers commonly ask automation candidates, with answers that reflect real test maintenance.
An implicit wait is a global setting that makes element lookups retry until the element exists or the timeout passes. An explicit wait targets one step and waits for a specific condition, such as an element being clickable. I prefer explicit waits because they are precise, and I do not mix the two because the timing becomes unpredictable.
I first find out why it fails by checking logs, screenshots and whether it fails at the same step. Usually the cause is a weak locator, a missing wait for the real condition, or shared test data. I fix that cause rather than adding retries or sleeps, which only hide the problem.
It means the element reference I stored no longer points to an element in the current page, because the page refreshed or part of it was re-rendered. The fix is to locate the element again after the change. In page objects I keep locators as By objects and find elements when needed, which avoids most cases.
It keeps locators and page actions in one class per page, so tests read like steps, such as loginPage.login(user, pass). When the UI changes, I update one class rather than every test that uses that page. It also reduces duplication and makes tests easier for new team members to read.
I use id or a test attribute when available, then CSS selectors because they are short and readable. I use XPath when I need to match visible text or move from one element to a related one, such as finding the button in the table row that contains a given order number. I avoid absolute paths in either.
I would switch into the iframe by name or element, fill the form, then switch back to the default content. After clicking pay, I would save the main window handle, wait for a second handle to appear, switch to it and verify the receipt. Finally I would close that tab and switch back to the main window.
Practise out loud. Say each answer once as written, then again in your own words with your own number or story.
Have a number ready. "My Selenium score is at benchmark on a timed test" is a stronger answer than "I am good at it". Take the test and quote the result.
More in Software testing