Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Selenium IDE’s documented Python export targets pytest, not unittest.TestCase. To use an exported script with unittest, export the test or suite, inspect the generated WebDriver code, then move each scenario into a discoverable TestCase method and put browser setup and cleanup in fixtures. For dynamic cases, use subTest() for related input variations or load_tests() to assemble a test suite during loading.
Can Selenium IDE import directly into unittest.TestCase?
Not through the documented standard Python export. Selenium IDE’s Code Export documentation lists Python with a pytest target; it does not document a built-in exporter that creates a unittest.TestCase module. Export is therefore a starting point for adaptation, not a promise that the resulting file is already a unittest test module. Check the export options in your installed IDE version, since the IDE export and plugin documentation surfaced with 2019 footer dates. Selenium IDE: Code Export
Selenium WebDriver code can still be organized and run with Python’s standard-library unittest framework. The practical conversion is structural: preserve the useful browser actions, assertions, and scenario logic, but place them within unittest’s test and fixture conventions. Selenium’s guide recognizes unittest as a Python framework option. Selenium: Organizing and Executing Selenium Code
Convert one exported scenario into a TestCase
Export a test or suite from Selenium IDE and read the generated Python before changing it. Create a module with a unittest.TestCase subclass, place one scenario in each method whose name begins with test_, and move browser creation and cleanup into fixture handling.
#1 Best Overall
import unittest
from selenium import webdriver
class RecordedFlowTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.addCleanup(self.driver.quit)
def test_recorded_flow(self):
# Move the exported WebDriver actions for one scenario here.
self.driver.get("https://example.test")
# Replace this with an assertion meaningful for your application.
self.assertIn("Example", self.driver.title)
if __name__ == "__main__":
unittest.main()
This is an illustrative structure, not code claimed to have been generated by Selenium IDE or run against a live application. Replace the example URL, browser choice, actions, and assertion with the values appropriate to your exported test and environment.
Use fixtures for browser lifetime
Unittest creates a fresh test-case fixture for each test method. Use setUp() to create the driver. Register self.addCleanup(self.driver.quit) immediately after driver creation so the cleanup is registered only once creation succeeds. Unittest runs registered cleanups through its cleanup handling, including when the test method fails. Alternatively, implement tearDown(); Python documents that it runs after a successful setUp(), even if the test method fails. Python: unittest — Unit testing framework
Keeping a scenario in its own method makes the failing scenario apparent in test output and prevents one long recording from hiding which behavior failed. If two IDE tests share setup logic, factor that logic into a helper method or a shared base class rather than relying on one test method to run before another.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Run and discover the module
Save the converted code in an importable Python module, with a filename such as test_recorded_flow.py and test methods named test_…. Run the file directly with python test_recorded_flow.py, or ask unittest to discover tests from the current directory with:
python -m unittest discover
For the standard module invocation, use:
python -m unittest test_recorded_flow
Discovery depends on importable module names and the test naming conventions, so confirm that the file is in the location you expect and that its class subclasses unittest.TestCase.
Rank #2
What to review when adapting exported code
Do not assume that a recorded command translates line-for-line into a maintainable unittest test. Review the generated file and confirm that the converted method preserves the intended behavior.
- Locators: Check locator strategies, selector text, and element assumptions against the current application. A selector that worked during recording may no longer identify the intended element.
- Waits: Replace timing assumptions with waits tied to the condition the scenario needs when the page loads asynchronously. Review any fixed delays rather than copying them automatically.
- Assertions: Make sure a test verifies an outcome, not merely that navigation or a click happened. Translate expected values into unittest assertions such as
assertEqual,assertTrue, orassertInas appropriate. - Variables and control flow: Preserve variable meaning and deliberately translate branches, loops, and JavaScript expressions. Selenium IDE documents control-flow commands and JavaScript expressions, but the appropriate Python equivalent depends on what the recorded scenario does. Selenium IDE: Control Flow
- Cleanup: Ensure browser shutdown is registered after successful startup. If setup adds more resources, register each cleanup as soon as that resource is acquired.
- Origin comments: Selenium IDE can include comments that trace generated lines to originating IDE steps. Enable them when available and useful for mapping actions back to the recording. They help with review; they do not establish that every command is supported by a custom unittest conversion.
Modify tests dynamically: choose the right unittest mechanism
“Modify dynamically” can mean either checking several related values in one method or deciding which test methods belong to a suite when unittest loads it. Those are different jobs.
Use subTest() for related variations
When the scenario is the same but its inputs vary, keep the scenario in one method and wrap each variation in self.subTest(). A failing subtest identifies the relevant parameter while allowing the method to report other variations too.
import unittest
class SearchValidationTest(unittest.TestCase):
def test_search_terms(self):
for term, expected_fragment in [
("books", "Books"),
("music", "Music"),
]:
with self.subTest(term=term):
# Replace this illustrative check with the Selenium actions
# and application assertion for the corresponding input.
self.assertTrue(expected_fragment)
In a browser test, put the appropriate navigation, input, and result check inside the subtest block. Decide whether each iteration needs a fresh page state or browser; a subtest does not automatically create a new TestCase fixture.
Use load_tests() to assemble a suite at load time
If test membership itself must be assembled when a module is loaded, implement the documented load_tests(loader, standard_tests, pattern) protocol and return a TestSuite. This customizes the suite returned during loading or discovery; it is not the same as putting several parameter checks inside one test method.
import unittest
class RecordedCase(unittest.TestCase):
def test_example(self):
self.assertTrue(True)
def load_tests(loader, standard_tests, pattern):
suite = unittest.TestSuite()
suite.addTests(standard_tests)
# Add or filter tests here when suite membership must be customized.
return suite
The example shows the loader hook’s shape, not an application-specific selection rule. Build or filter cases according to your own data and return the resulting suite. Python’s unittest documentation describes the loader, suite, and subtest APIs. Python: unittest — Unit testing framework
Prefer explicit methods unless dynamic names are necessary
For a fixed set of recorded IDE scenarios, write explicit test_… methods. For related variations, use subtests. Use load_tests() when suite construction during loading is the actual requirement. Python permits dynamically creating methods, but the unittest documentation cited here does not recommend method injection as the default migration pattern; it can also make test discovery and failure names harder to follow.
Why exported Python may not run as unittest code
The documented Python code-export target is pytest. That explains why an export should not be treated as a ready-made unittest.TestCase module: the generated structure and framework conventions may differ from the test runner you intend to use. It does not establish that a particular export is broken, nor that all exports need the same edits.
Selenium IDE’s command-line runner is another distinct option: it runs .side projects, with runner configuration, filtering, and result output. The runner is not the same as exporting WebDriver code for a custom Python test framework. The runner documentation points readers seeking code translation or custom framework integration toward code export. Selenium IDE: Command-line Runner
The IDE’s code-export plugin API documents language IDs such as python-pytest and hooks for export behavior, including setup, teardown, variables, and dependencies. That is an extension route, not evidence that the standard IDE provides a built-in unittest exporter. A custom exporter would need to generate unittest-compatible structure and correctly map the commands it supports. Selenium IDE: Code Export Plugin Support
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchTroubleshooting common conversion problems
Unittest reports no tests
Check that the class inherits from unittest.TestCase, each intended test method starts with test_, and the module is importable. When using discovery, check the filename and run discovery from the directory that contains or can import the module.
The exported file expects pytest
Do not solve this by assuming unittest can run pytest-specific structure unchanged. Create a unittest module, move the scenario actions into test methods, use unittest assertions, and place browser lifecycle code in fixtures. Inspect the actual output because the precise changes depend on the export.
The browser starts but remains open after a failure
Register self.addCleanup(self.driver.quit) immediately after driver creation, or implement tearDown() for a successfully initialized driver. Do not register cleanup before the driver exists.
A recorded step fails intermittently
Review page readiness and element conditions. A recorded delay may not match the application’s load behavior; use a condition-based wait for the relevant element or state, then make the assertion. Also confirm that selectors and expected content still match the application.
Variables or branches behave differently
Review the IDE’s control-flow commands and JavaScript expressions and translate their behavior intentionally into Python. A direct textual copy may not preserve the branch, loop, or variable semantics.
Best Value
Suite customization does not happen
Confirm that load_tests has the documented parameters and returns a unittest.TestSuite. Use it for suite composition at load time; use subTest() instead when the suite is fixed and only the input values vary within a scenario.
Or skip the browser setup
If your goal is to capture a web page rather than run an interactive Selenium test, ScreenshotNeo offers a website screenshot API and MCP server for developers. One GET request can return PNG, JPEG, WebP, or PDF. Its clean-shot process accepts consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients.
For a runnable cURL example, replace the placeholder with your API key. The URL parameter below is passed with --data-urlencode:
Recommended Free Tools
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for API details. This is a screenshot call, not a conversion of a Selenium IDE scenario into a unittest test.
- Cookie banners, popups, and chat widgets are removed before the shot.
- Bot checks, blank pages, and failed loads are never billed.
- An MCP server lets AI agents take screenshots.
- The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for 1,000 free screenshots a month—no card required.
Frequently Asked Questions
Does Selenium IDE’s documented Python export produce a unittest module?
No. Its documented Python export target is pytest; adapt the exported WebDriver code for unittest.
Should I use subTest or load_tests for dynamic cases?
Use subTest for related input variations inside a test method; use load_tests when you need to customize the suite during loading.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsDoes the ScreenshotNeo example convert a Selenium IDE recording?
No. It captures a page through an API; it does not run or convert an IDE test scenario.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

