A Bug-Hunter’s Guide to Nailing Selenium Interview Questions — Part III

Nurhayat Koklu
4 min readAug 10, 2023

--

Hey there, fellow QA Automation Engineers! Are you ready to set sail on another thrilling journey through the realm of Selenium? We’ve already embarked on our voyage to understand the essence of Selenium and the intricate art of locating elusive WebElements. If you’ve missed those chapters, you can catch up on those exciting quests by checking A Bug-Hunter’s Guide to Nailing Selenium Interview Questions — Part I and A Bug-Hunter’s Guide to Nailing Selenium Interview Questions — Part II. Now, with a hearty spirit and a keen eye for learning, let’s dive into the third part of our Selenium saga — the mesmerizing world of waits.

As a seasoned software QA engineer, I’ve weathered many stormy coding challenges. But the topic of waits in Selenium is like the constantly shifting tides — intricate and sometimes tricky to navigate. Fear not, for I shall be your trusty guide as we navigate these waters together, unraveling the mysteries of waits in Selenium.

A Glimpse into the Enchanting World of Waits

Imagine this scenario: you’re exploring a bustling marketplace, but the merchants’ stalls appear at different times. Similarly, web applications, often powered by the magic of Ajax and JavaScript, might not present the elements we seek to interact with right away. As the webpage unfolds, we might find ourselves facing the dreaded “ElementNotVisibleException” or “NoSuchElementException” exceptions — like trying to buy from a vendor whose stall hasn’t yet appeared.

Enter the mystical power of waits, our trusty companions in the land of Selenium. Selenium offers us two types of waits — Implicit Wait and Explicit Wait — each serving a unique purpose in our quest for seamless test scripts.

  1. Implicit Wait: The Silent Guardian

Picture this: you’re strolling through a magical forest, and every time you approach a clearing, you pause for a moment to admire its beauty. Implicit Wait is akin to this silent pause. When we employ Implicit Wait in our Selenium WebDriver, we instruct it to wait for a specific duration before it decides to throw a “NoSuchElementException” exception. This patient guardian watches over all elements within the script, giving them time to gracefully appear before we interact with them.

2. Explicit Wait: The Specialist Sorcerer

Ah, Explicit Wait, the specialist sorcerer in our wait arsenal! This magical art allows us to specify precise conditions that must be met before our interactions commence. Gone are the days of wrestling with the “ElementNotVisibleException” turmoil. With Explicit Wait, we declare an expected condition for a specific element, ensuring it’s ready for our interactions before we proceed. This becomes particularly handy as elements may choose to reveal themselves at their own leisurely pace.

As we traverse this enchanted realm, let’s unveil some of the mystical conditions we can conjure with Explicit Wait:

  • alertIsPresent(): A spell for detecting unexpected pop-ups.
  • elementToBeClickable(): Ensures the element is ready to accept our clicks.
  • elementToBeSelected(): Checks if an element, like a checkbox, is ready for selection.
  • titleIs(): A spell that waits for a specific page title to appear.
  • visibilityOf(): Keeps vigil until an element becomes visible.

But hold your breath, for there’s one more treasure to uncover — the elusive Fluent Wait.

3. Fluent Wait: The Time Weaver

Imagine a weaver who masterfully wields time, crafting a tapestry of patience and precision. That’s the essence of Fluent Wait. With this potent incantation, we set a maximum waiting time and a frequency at which our WebDriver checks for a condition to be met. It’s like having a sentinel guarding over a specific element, watching, and waiting until the conditions are met or the sands of time run out.

As we near the end of this captivating chapter, my fellow QA adventurers, keep in mind that confidently addressing questions about waits in technical interviews is like hoisting your sails in a storm — it’s a mark of skill and experience. Remember to mention your avoidance of the slumber-inducing Thread.sleep(), and you’ll surely earn the admiration of interviewers and fellow mariners.

With this newfound knowledge, you’re well-equipped to tame the tempestuous seas of Selenium waits, ensuring your test scripts sail as smoothly as a ship guided by the North Star. So, fellow mariners of Selenium, set forth on your coding odyssey, and may your interviews be as tranquil as a calm sea at sunrise. Until we meet again, may your coding journeys be ever full of wonder and discovery!

--

--

Nurhayat Koklu
Nurhayat Koklu

Written by Nurhayat Koklu

Software Developer in Test 🚀 | Passionate about quality and reliable software | Exploring the digital world one bug at a time 🐛

Responses (1)