SeleniumHQ/selenium · error · AttributeError

module {__name__!r} has no attribute {name!r}

Error message

module {__name__!r} has no attribute {name!r}

What it means

Raised by the module-level __getattr__ in selenium.webdriver.webkitgtk.__init__ when an attribute name is accessed that is not one of the lazily-loadable submodules ('options', 'service', 'webdriver'). This is a PEP 562 lazy import pattern: the three submodules are imported on first access and cached in globals(), while any other name raises a standard AttributeError. This mirrors Python's built-in behavior for missing module attributes.

Source

Thrown at py/selenium/webdriver/webkitgtk/__init__.py:28

#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

import importlib

_LAZY_SUBMODULES = ["options", "service", "webdriver"]


def __getattr__(name):
    if name in _LAZY_SUBMODULES:
        module = importlib.import_module(f".{name}", __name__)
        globals()[name] = module
        return module
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


def __dir__():
    return sorted(_LAZY_SUBMODULES)

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Use the correct submodule names: webkitgtk.options, webkitgtk.service, webkitgtk.webdriver.
  2. Import classes from their submodule: from selenium.webdriver.webkitgtk.options import Options.
  3. Check dir(webkitgtk) to see the available submodules (the __dir__ implementation returns sorted(_LAZY_SUBMODULES)).
  4. Verify spelling and case — submodule names are lowercase, class names are CamelCase.

Example fix

// before
from selenium.webdriver import webkitgtk
driver_class = webkitgtk.WebDriver  # AttributeError
// after
from selenium.webdriver.webkitgtk.webdriver import WebDriver
driver_class = WebDriver
Defensive patterns

Strategy: validation

Validate before calling

from selenium.webdriver import webkitgtk

AVAILABLE = dir(webkitgtk)  # ['options', 'service', 'webdriver']
if 'webdriver' in AVAILABLE:
    from selenium.webdriver.webkitgtk.webdriver import WebDriver

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Accessing an attribute on the webkitgtk package that does not exist: e.g., from selenium.webdriver import webkitgtk; webkitgtk.WebDriver (capital W, wrong case) or webkitgtk.some_helper (nonexistent). Also triggered by typo in submodule name or accessing an internal helper that was never exported.

Common situations: Typo in the submodule or class name (e.g., Options with capital O vs options lowercase); trying to import a class directly from the package root when it lives in a submodule; code completion suggesting a wrong name; migrating from an older API where the attribute existed but was since removed or renamed.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/ccb069ffc6568afe. Report an issue: GitHub.