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
Module-level __getattr__ in selenium.webdriver.safari implements lazy submodule loading for a fixed allowlist (options, permissions, remote_connection, service, webdriver). Accessing any attribute outside that allowlist raises AttributeError naming the module and the missing attribute.
Source
Thrown at py/selenium/webdriver/safari/__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", "permissions", "remote_connection", "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
- Check spelling against the allowlist: options, permissions, remote_connection, service, webdriver.
- Import the submodule directly: `from selenium.webdriver.safari import service`.
- Consult the current API docs for the correct public name.
Example fix
# before from selenium.webdriver import safari svc = safari.srvc # typo -> AttributeError # after from selenium.webdriver.safari import service as svc
Defensive patterns
Strategy: validation
Validate before calling
from selenium.webdriver import safari
name = "service"
if name not in dir(safari) and name not in ("options","permissions","remote_connection","service","webdriver"):
raise AttributeError(f"safari has no lazy submodule {name}") Type guard
from selenium.webdriver import safari
_LAZY = {"options","permissions","remote_connection","service","webdriver"}
def has_safari_attr(name: str) -> bool:
return name in _LAZY Prevention
- Use explicit submodule imports rather than attribute access on the package.
- Cross-check attribute names against the lazy allowlist before dynamic access.
When it happens
Trigger: 1) selenium.webdriver.safari.<typo> for a name not in the allowlist. 2) hasattr/getattr probes or IDE autocompletion guesses. 3) Migration code expecting an attribute that was renamed/removed.
Common situations: Renamed internals across versions, a typo in the import path, or accessing a private name that is not lazily exported.
Related errors
- module {__name__!r} has no attribute {name!r}
- module {__name__!r} has no attribute {name!r}
- module {__name__!r} has no attribute {name!r}
- module 'selenium.webdriver' has no attribute {name!r}
- module {__name__!r} has no attribute {name!r}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/4bbc008b1d569ee0.
Report an issue: GitHub.