Description
What happened?
When running Selenium on a "pure IPv6" system where all IPv4 interfaces have been removed, the FindFreePort method, which is used to find a free TCP port to use on the loopback interface for communication to the browser driver, fails since it is hard coded for IPv4 and there are no IPv4 interfaces.
(https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/Internal/PortUtilities.cs) Line 40
Socket portSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
AddressFamily.InterNetwork is IPv4. AddressFamily.InterNetworkV6 is IPv6.
In Pure IPv6 environment, attempt create the Browser Driver object fails with exception: "An address incompatible with the requested protocol was used"
How can we reproduce the issue?
On windows host where selenium is being executed:
-Ensure IPv6 is working as expected
-Remove IPv4 by running: netsh interface ipv4 uninstall
-Reboot for uninstall to complete
-Attempt to use Selenium
The below PowerShell code could be used for example. Just place the WebDriver.dll and selected browserdriver.exe in the same directory as the saved PowerShell script and execute:
Function Get-Browser {
Param (
[Parameter(Mandatory=$true)]
[ValidateSet("Edge","Chrome")]
[string]$type
)
Set-EnvironmentPath
Add-Type -Path "$($PSScriptRoot)\WebDriver.dll"
Switch ($type) {
"edge" {
$Driver = New-Object OpenQA.Selenium.Edge.EdgeDriver
}
"chrome" {
$Driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
}
}
$Driver
}
Function Set-EnvironmentPath {
# Add the working directory of script to the environment path.
# This is required for the WebDriver to work.
if (($env:Path -split ';') -notcontains $PSScriptRoot)
{
Write-Verbose -Message "Enviornment path does not contain $PSScriptRoot. Adding to Path"
if ($env:Path.Substring($env:Path.Length-1) -eq ';')
{
$env:Path += "$PSScriptRoot"
}
else
{
$env:Path += ";$PSScriptRoot"
}
}
}
$browser = Get-Browser -type Edge
Relevant log output
New-Object : Exception calling ".ctor" with "0" argument(s): "An address incompatible with the requested protocol was used"
At C:\WebDev\Start-Selenium.ps1:14 char:29
+ ... $Driver = New-Object OpenQA.Selenium.Edge.EdgeDriver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Operating System
Windows 2019
Selenium version
PowerShell
What are the browser(s) and version(s) where you see this issue?
Edge 131.0.2903.86
What are the browser driver(s) and version(s) where you see this issue?
Microsoft Edge WebDriver 131.0.2903.99 (f96a870b1316f430223b7df17df32918b222060e)
Are you using Selenium Grid?
No