SeleniumHQ/selenium · warning · WebDriverException
Port needs to be an integer
Error message
Port needs to be an integer
What it means
Raised by the (deprecated) FirefoxProfile.port setter when the value is not an int. This is the first guard in the setter; it rejects non-int types outright before attempting any range or coercion logic. The entire port property is deprecated — port should be set on the Firefox Service, not the profile.
Source
Thrown at py/selenium/webdriver/firefox/firefox_profile.py:113
# Properties
@property
def path(self):
"""Gets the profile directory that is currently being used."""
return self._profile_dir
@property
@deprecated("The port is stored in the Service class")
def port(self):
"""Gets the port that WebDriver is working on."""
return self._port
@port.setter
@deprecated("The port is stored in the Service class")
def port(self, port) -> None:
"""Sets the port that WebDriver will be running on."""
if not isinstance(port, int):
raise WebDriverException("Port needs to be an integer")
try:
port = int(port)
if port < 1 or port > 65535:
raise WebDriverException("Port number must be in the range 1..65535")
except (ValueError, TypeError):
raise WebDriverException("Port needs to be an integer")
self._port = port
self.set_preference("webdriver_firefox_port", self._port)
@property
@deprecated("Allowing untrusted certs is toggled in the Options class")
def accept_untrusted_certs(self):
return self._desired_preferences["webdriver_accept_untrusted_certs"]
@accept_untrusted_certs.setter
@deprecated("Allowing untrusted certs is toggled in the Options class")
def accept_untrusted_certs(self, value) -> None:
if not isinstance(value, bool):View on GitHub (pinned to aa36b38e69)
Solutions
- Stop using profile.port — set the port on the Firefox Service instead: Service(port=7042).
- If you must use the deprecated API, pass an int: profile.port = 7042.
- Convert config values to int before assignment: profile.port = int(value).
Example fix
# before (deprecated path) profile = FirefoxProfile() profile.port = '7042' # -> WebDriverException # after — set port on the Service from selenium.webdriver.firefox.service import Service service = Service(port=7042) driver = webdriver.Firefox(service=service)
Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(port, int) and not isinstance(port, bool), 'port must be a plain int' profile.port = port
Type guard
def is_plain_int(v) -> bool:
return isinstance(v, int) and not isinstance(v, bool) Try / catch
from selenium.common.exceptions import WebDriverException
try:
profile.port = raw
except WebDriverException:
profile.port = int(raw) Prevention
- Prefer setting port on the Firefox Service instead of the deprecated profile.port.
- Coerce config strings to int before assignment.
- Treat any use of profile.port as legacy code to migrate.
When it happens
Trigger: Assigning profile.port = '7042' or profile.port = 7042.0 (a float) triggers this immediately because isinstance(port, int) is False for strings and floats. Note: a bool would pass this check (bool is a subclass of int) but then fail range validation.
Common situations: Using legacy code or examples that set profile.port, passing a value parsed from config as a string, or migrating old Selenium 3 code. The deprecation warning should already steer users away.
Related errors
- Please pass in a Boolean to this call
- Port number must be in the range 1..65535
- unable to find profile named: #{name.inspect}
- not a string or number
- Timeouts can only be an int or a float
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/23dbc7a3942b298c.
Report an issue: GitHub.