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.wpewebkit.__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 identical to the webkitgtk package: submodules are imported on first access, any other name raises AttributeError.

Source

Thrown at py/selenium/webdriver/wpewebkit/__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: wpewebkit.options, wpewebkit.service, wpewebkit.webdriver.
  2. Import from the submodule: from selenium.webdriver.wpewebkit.options import Options.
  3. Check dir(wpewebkit) to see available submodules.
  4. Verify spelling and case.

Example fix

// before
from selenium.webdriver import wpewebkit
svc = wpewebkit.service  # might work, but:
bad = wpewebkit.services  # typo -> AttributeError
// after
from selenium.webdriver.wpewebkit.service import Service
svc = Service()
Defensive patterns

Strategy: validation

Validate before calling

from selenium.webdriver import wpewebkit

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

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Accessing an attribute on the wpewebkit package that does not exist: e.g., wpewebkit.options with a typo, or wpewebkit.SomeClass at the package root. Also triggered by incorrect capitalization or trying to reach an internal module that was never part of _LAZY_SUBMODULES.

Common situations: Typo in submodule or class name; importing a class from the package root instead of the submodule; code completion suggesting a wrong attribute; confusion between package-level and submodule-level access patterns.

Related errors


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