What to avoid when writing Selenium test scripts?

June 11, 2026 · 7 min read · Tool Comparison

Blog / Insights /
What to debar when writing Selenium trial script?

What to avoid when write Selenium tryout scripts?

QA Consultant Updated on

Learn with AI

Linkedin

Facebook

X (Twitter)

Mail

Learn with AI

Selenium do browser automation easy to get started with. But writing stable, maintainable tryout scripts is a unhurt other story.

At first, everything works fine, then a button moves, or a page lade slower than expected, or your handwriting Newmarket right in the middle of a checkout flow. You end up debugging for hours only to realize that the test is brittle. Now imagine that happening across scores of scripts.

Selenium command scripts are only as reliable as the practices behind them. The incorrect habits like hardcoded waits or wretched locator selection can turn your exam into time-wasting liabilities. And that ’ s what we want to help you avoid.

In this clause, we ’ ll walk throughsix common mistakes testers do when indite Selenium scripts. You ’ ll see what not to do, and more importantly, what to do instead.

Here ’ s what we ’ ll cover:

  • Why hardcoded waits break more than they fix
  • How to write locators that survive UI alteration
  • Why page sync issue lead to test flakiness
  • How to manage exam data the right way
  • How to prevent test crashes with error treatment
  • How to write cleaner, modular scripts that scale

Let ’ s dive in and start fixing what is often overlooked in Selenium script design.

6 things to avert when make Selenium test playscript

1. Using hardcoded waits

Hardcoded waits tell your test to pause for a fixed amount of time. This might appear safe, but it often leads to longer runtimes and brickle book. If the application lade faster or slower than expected, the script either wastes time or fails accidentally.

A better approach is to useexplicit waits. These waits allow the test to proceed as presently as the element appear or become ready. That intend your scripts are more responsive and reliable in different environments.

Here is a short before-and-after model.

Python
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import clip driver = webdriver.Chrome () driver.get (`` https: //katalon.com '') # BEFORE: set wait time.sleep (5) banner = driver.find_element (By.ID, `` main-banner '') # AFTER: explicit waiting wait = WebDriverWait (driver, 10) banner = wait.until (EC.visibility_of_element_located ((By.ID, `` main-banner ''))) print (`` Banner loaded: '', banner.text) driver.quit ()

2. Writing locater that are too slight

Locators define how your test finds an component, so if that locator bet on unstable attributes, it can separate every time the UI modification slightly. Long XPath expressions and auto-generated IDs much change between builds or deployment.

To build handwriting that last, you should take locater character that remain consistent over time. Stable locator help you reduce maintenance and meliorate test stableness across releases.

Here are authentic locater types to use:

  • ID: Ideal when available, fast and specific
  • Name: Helpful for kind battlefield and measure inputs
  • CSS Selector: Clean, fast, and easy to read

Review your locator strategy before you finalize any playscript. Look for the simplest, most stable option first. This habit meliorate every test and aligns with best recitation in any Selenium locater strategy.

💡 Read more: Locators in Selenium: How to use them

3. Ignoring page synchronicity

Every web application responds in its own time. Some elements look forthwith, while others direct a moment. When your script attempt to interact with something that is not ready, you may see an fault like `` NoSuchElementException ''.

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

You can handle this with chic expect. Instead of guessing when the page is ready, wait for a specific condition. One common example is to wait until an element becomes clickable. This gives your test a smooth flowing and prevents timing issues.

Here is a simple way to await before typing into a hunting box.

Python
from selenium signification webdriver from selenium.webdriver.common.by importee By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support importee expected_conditions as EC driver = webdriver.Chrome () driver.get (`` https: //katalon.com '') await = WebDriverWait (driver, 10) search_box = wait.until (EC.element_to_be_clickable ((By.ID, `` search-bar ''))) search_box.send_keys (`` automation testing '') driver.quit ()

Waiting with intention give your script time to breathe. It also ensures that the succeeding action lands exactly where it should.

💡Read more:How to handle Selenium timeouts?

4. Skipping test data management

Hardcoding value inside your exam script works for pocket-size demos, but it set reusability. Each clip you desire to try a new scenario, you must update the script manually, and that slows you down and increase maintenance.

By using variables or loading information from a file, your script becomes more pliable. You can run the same test logic across multiple datum set without rewrite anything.

Here is a simple comparison:

Approach Test Value Source Flexibility
Hardcoded Directly in handwriting Low
Parameterized Varying or external source High

You can get simple by store tryout comment in a list or a file the feed them into your hand as demand.

💡Read more:A guide to test information management

5. Not plow exceptions properly

In every automation suite, thing sometimes go off path. A popup seem, a button disappears, or the network meanwhile. With proper exception handling, your test can stay on course and give you useful feedback.

Try-catch cube give you moderate when something unexpected happens. You can log the issue, skip to the future measure, or retry the action. This make the entourage more resilient and avoids sudden Chicago.

Here is a simple example that handles a wanting ingredient and logs the error.

Python
from selenium.common.exceptions import NoSuchElementException try: driver.find_element (By.ID, `` promo-banner '') .click () except NoSuchElementException as e: print (`` Element not found. Skipping promo banner. '') print (`` Error message: '', e)

Logging helps you describe problem after a run. You can store messages in a file, send alerts, or print them in the console. Clear log give you insight without stopping the stream of the tryout retinue.

6. Overcomplicating handwriting

Simple scripts are easier to maintain. When your test logic lives in one long block, it go hard to read, debug, and extend. A more effective scheme is to separate your scripts into small reusable parts.

Functions aid you repeat actions cleanly. Page Object Models give structure to how your script interacts with each page. These techniques make your Selenium automation easier to scale and fast to update.

If you want to postdate good Selenium good practices, start with this mindset: build for lucidity, not precisely for role.

Here are mark a script is ready to be modularized:

  • You scroll a lot to find what the script is doing
  • You copy and paste the same step more than once
  • You avoid editing it because the structure is unclear

Breaking things down betimes & nbsp; saves time later and supports a more maintainable test procedure for the unscathed squad.

Why choose Katalon to automate tests?

is a trial automation program that helps teams travel faster without sacrificing stability. It takes everything great in Selenium and get it easygoing, smarter, and more generative to manage.

With Katalon, you get:

  • A accomplished environment for designing, mastermind, and running automated tests. You can manage locators, information sets, and reports all in one place.
  • Out-of-the-box support for multiple browser, devices, and environs. You can run tests locally, on cloud service, or inside CI grapevine with zero extra setup.
  • Smart wait manipulation and locator recovery powered by AI. Your tests bide stable still as the UI changes over time.
  • Powerful analytics and reporting dashboards that show you test health, execution, and coverage at a glance.
  • Built-in integrations with your preferent tools like Jenkins, GitHub, Azure DevOps, and Jira. Everything flows from commit to deploy with self-assurance.

In short, Katalon reduces the travail of maintaining Selenium test scripts. It afford teams a smarter way to scale mechanization without slacken down.

📝 Want to explore what Katalon can do for your team?Request a demoto see how it helps teams automate faster with less endeavor.

Explain

|

FAQs

Why are hardcoded waits a bad pattern in Selenium tests?

+

Hardcoded hold pause tests for a fixed time, leading to slow trial when Page load quickly and brittle failures when pages load slowly, whereas explicit waits let trial continue as soon as conditions are met, making scripts quicker and more true.

What makes a Selenium locator “ fragile, ” and how can you avoid that?

+

Fragile locators calculate on unstable attributes like long XPaths or auto-generated IDs that break whenever the UI changes; habituate stable IDs, names, or clear CSS selectors makes locater more full-bodied and reduces upkeep.

How do page synchronization issues cause flaky Selenium tests?

+

If scripts try to interact with elements before they are ready, you get error likeNoSuchElementException. Using explicit postponement for conditions such as visibility or clickability keeps tests synchronized with the application and prevents timing-related craziness.

Why is proper examination information management significant in Selenium automation?

+

Hardcoding value inside scripts limits reusability and forces manual edits for every new scenario; parameterized data or external datum sources let the same logic run across multiple stimulus, making tests more pliant and scalable.

How can modular plan and exception handling improve Selenium test suites?

+

Breaking scripts into reclaimable functions or page aim, and using try–catch blocks with clear logging, makes examination easier to maintain, more resilient to unexpected issues, and simpler to debug when something goes improper.

Vincent N.
QA Consultant
Vincent Nguyen is a QA adviser with in-depth domain knowledge in QA, software testing, and DevOps. He has 5+ years of experience in crafting content that resonate with techie at all levels. His interests span from writing, technology, to construct nerveless stuff.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free