---
title: Selenium Python Quiz | Selenium with Python and pytest
description: Ten questions on the decisions this course made and why. Each answer
  explains the reasoning once you check. The quiz is a self-check; nothing is recorded.
  1.…
source_url:
  html: https://testingbot.com/resources/courses/selenium-python/knowledge-check
  md: https://testingbot.com/resources/courses/selenium-python/knowledge-check.md
---

Course

[Selenium with Python and pytest](https://testingbot.com/resources/courses/selenium-python)

Chapter 10 of 10

1. [1 Selenium Python Tutorial with pytest](https://testingbot.com/resources/courses/selenium-python)
2. [2 Set up Selenium with Python and pytest](https://testingbot.com/resources/courses/selenium-python/setup-and-first-test)
3. [3 Selenium locators in Python: the By API](https://testingbot.com/resources/courses/selenium-python/locators)
4. [4 Selenium waits in Python: WebDriverWait and time.sleep](https://testingbot.com/resources/courses/selenium-python/waits)
5. [5 pytest fixtures for Selenium: conftest.py and scope](https://testingbot.com/resources/courses/selenium-python/pytest-fixtures)
6. [6 Assertions, screenshots on failure and test reports](https://testingbot.com/resources/courses/selenium-python/assertions-screenshots-reports)
7. [7 Page objects in Python](https://testingbot.com/resources/courses/selenium-python/page-objects)
8. [8 Run Selenium tests in parallel with pytest-xdist](https://testingbot.com/resources/courses/selenium-python/parallel-with-pytest-xdist)
9. [9 Run Selenium Python tests on the TestingBot grid](https://testingbot.com/resources/courses/selenium-python/run-on-testingbot)
10. [10 Selenium Python Quiz](https://testingbot.com/resources/courses/selenium-python/knowledge-check)

[Exit course](https://testingbot.com/resources/courses)

 Chapter 10 of 10 Intermediate 6 min read Updated Nov 2026 

# Selenium Python Quiz

Ten questions on the decisions this course made and why. Each answer explains the reasoning once you check. The quiz is a self-check; nothing is recorded.

1. Code copied from an old tutorial calls `driver.find_element_by_id("email")` and fails on Selenium 4.52 with `AttributeError`. What is the fix?

 Downgrade Selenium until the method exists again. Use `driver.find_element(By.ID, "email")`; the `find_element_by_*` helpers were removed in Selenium 4. Install a newer chromedriver.

Selenium 4 replaced the per-strategy helpers with `find_element(By.X, value)`, and 4.3 removed the old ones. Downgrading locks you out of current browsers, and the driver binary has nothing to do with the Python API.

2. You add `tests/login_checks.py` with a function `test_login`, but `pytest` reports "no tests ran". Why?

 By default pytest only collects files named `test_*.py` or `*_test.py`. The function needs a `@pytest.mark.test` decorator. Test files must be imported from `conftest.py`.

Discovery is name-based: rename the file to `test_login.py`. pytest needs no decorator to find a `test_` function, and nothing should import test files.

3. `wait.until(EC.element_to_be_clickable(By.ID, "save"))` raises `TypeError`. What is wrong?

 `element_to_be_clickable` only accepts an element, not a locator. The wait has no timeout. Expected conditions take one locator tuple: `EC.element_to_be_clickable((By.ID, "save"))`.

The condition's single argument is the tuple `(By.ID, "save")`. Passing two separate arguments is a Python `TypeError` before any waiting happens. The condition accepts either a locator tuple or an element.

4. A fixture sets `driver.implicitly_wait(10)` and the tests use `WebDriverWait(driver, 15)`. Some failures take around 20 seconds to report. Why?

 The grid adds a fixed 5-second delay to every command. Mixing implicit and explicit waits makes timing unpredictable, because element lookups inside the explicit wait also wait implicitly. `WebDriverWait` always rounds up to the next 10 seconds.

Each poll of the explicit wait can block for the implicit timeout, so the combined wait overshoots. The Selenium docs give this exact example. Keep the implicit wait at 0 and use explicit waits.

5. In a `yield` fixture, the test body raises an `AssertionError`. What happens to the code after `yield`?

 It runs, so the browser is still closed. It is skipped, so you need `try`/`finally` in every test. It runs only when pytest is started with `--teardown`.

pytest runs fixture teardown after the test regardless of the outcome. That is why the fixture can replace the `try`/`finally` from the first chapter. Teardown is skipped only if the fixture's own setup failed before reaching `yield`.

6. A test is decorated with `@pytest.mark.parametrize("value", ["a", "b", "c"])` and uses the `driver` fixture. You run `pytest --browser chrome --browser firefox`. How many test items does it produce?

 3 5 6

Parametrisations multiply: three values times two browsers. Each combination is a separate test with its own ID, such as `[firefox-b]`, and its own browser.

7. Why does the course's `conftest.py` implement `pytest_runtest_makereport`?

 To generate the HTML report. To store each phase's report on the test item, so the fixture's teardown can tell whether the test failed. To retry failed tests automatically.

Fixtures do not receive the test outcome. The hook saves it as `rep_call` on the item, and the fixture reads `request.node.rep_call` to decide on a screenshot and the grid status. HTML reports come from pytest-html, and the hook retries nothing.

8. In the page object, locators are tuples such as `SUBMIT = (By.CSS_SELECTOR, "button[type='submit']")`. Why write `find_element(*self.SUBMIT)`?

 The star unpacks the tuple into the two arguments `find_element` expects, and the same tuple can be passed whole to expected conditions. The star makes Selenium wait for the element. The star finds all matching elements instead of the first.

`*` is Python argument unpacking: `find_element(*("css selector", "..."))` is `find_element("css selector", "...")`. It adds no waiting, and `find_elements` is how you get all matches.

9. A test file keeps a module-level list of the users its tests created, and a final test asserts the list has five entries. It passes with `-n 0` and fails with `-n 4`. Why?

 pytest-xdist clears module variables after every test. Lists are not thread-safe in Python. Workers are separate processes with their own copy of the module, and the tests are spread across them, so no single list sees all five users.

xdist uses processes, not threads, and does not guarantee which worker runs which test or in what order. The real problem is that the last test depends on the others; each test should set up and check its own data.

10. A pull request puts the TestingBot key and secret directly into `conftest.py` "so CI works". What should you ask for instead?

 Move them into `pytest.ini`, which is not Python code. Read them from `TB_KEY` and `TB_SECRET` environment variables, set from CI secrets, and rotate the leaked pair. Base64-encode them before committing.

Anything committed, in any file or encoding, is readable by everyone with repository access and stays in the history. Environment variables filled from CI secrets keep credentials out of the code, and a leaked pair should be replaced.

Check answers

## Where to go next[#](https://testingbot.com#where-to-go-next)

- Run the suite on more browser and OS combinations with the [capabilities generator](https://testingbot.com/support/web-automate/selenium/capabilities).
- Grow the page objects into a framework with the [Page Object Model course](https://testingbot.com/resources/courses/page-object-model).
- See the same suite in Java in [Selenium with Java and TestNG](https://testingbot.com/resources/courses/selenium-testng), or compare a different tool in the [Playwright course](https://testingbot.com/resources/courses/playwright).
- Prepare for interviews with the [Selenium interview questions](https://testingbot.com/resources/courses/selenium-interview-questions).

[Previous · Chapter 9 Run Selenium Python tests on the TestingBot grid](https://testingbot.com/resources/courses/selenium-python/run-on-testingbot)
## You finished Selenium with Python and pytest

Put what you learned into practice. Run your tests on 6100+ real browsers and physical iOS and Android devices.

[Start free trial](https://testingbot.com/users/sign_up) [See pricing](https://testingbot.com/pricing) [Browse other courses](https://testingbot.com/resources/courses)

## Earn the TestingBot certification for this course

Pass the exam and run the course suite on TestingBot. Free, with a public link you can add to LinkedIn.

[How it works](https://testingbot.com/resources/courses/selenium-python/certification)
