How do I connect to an existing Driver with IP/Port? (.Net)

204 views
Skip to first unread message

ili

unread,
Mar 29, 2016, 10:43:23 PM3/29/16
to Selenium Users
Hi
I use Selenium true Powershell to Open EdgeDriver locally and it works great.

Now I want to open the MicrosoftWebDriver.exe manually on one server and then run the Powershell Selenium script on another server by connecting to the MicrosoftWebDriver on the other server by IP and Port
I cant understand from the documentation what is the syntax to do that

The beginning of my correct script that works locally is:

# Load the web driver dlls
$dllroot
= 'C:\Program Files (x86)\Microsoft Web Driver\'
Add-Type -Path  (Join-Path -Path $dllroot -ChildPath Selenium.WebDriverBackedSelenium.dll)
Add-Type -Path (Join-Path -Path $dllroot -ChildPath ThoughtWorks.Selenium.Core.dll)
Add-Type -Path (Join-Path -Path $dllroot -ChildPath WebDriver.dll)
Add-Type -Path (Join-Path -Path $dllroot -ChildPath WebDriver.Support.dll)

# Initiate a driver
$driver = New-Object -TypeName OpenQA.Selenium.Edge.EdgeDriver

# Browse to a website
$driver.Url = '
https://google.com'

Now how do I create the "$driver" by connecting to the MicrosoftWebDriver.exe by IP and Port and not by putting it in the same folder as in this example?

Thank you

Jim Evans

unread,
Mar 30, 2016, 6:23:26 AM3/30/16
to Selenium Users
You don't. Most driver server executables (chromedriver.exe, IEDriverServer.exe, and I suspect MicrosoftWebDriver.exe) restrict connections to localhost only. Additionally, the language bindings typically do not expose remote connection ability through the browser-specific driver classes, and the .NET bindings are no exception. However, you can use the RemoteWebDriver class in the .NET bindings on your local machine along with the Java Selenium standalone server on the remote machine to accomplish your goal of remote execution.
Message has been deleted
Message has been deleted

ili

unread,
Mar 30, 2016, 1:24:55 PM3/30/16
to Selenium Users
Hi
I don't see a problem running commands remotely on the MicrosoftWebDriver.exe Driver:

# Run on Remote Server as Administrator
.'C:\Program Files (x86)\Microsoft Web Driver\MicrosoftWebDriver.exe' --host=Win10

# Run On the Client Machine
Invoke-RestMethod -Uri http://Win10:17556/status -Method Get

$Obj
= [PsCustomObject]@{desiredCapabilities = [PsCustomObject]@{}; requiredCapabilities = [PsCustomObject]@{}} | ConvertTo-Json
$O
= Invoke-RestMethod -Uri http://Win10:17556/session -Method Post -Body $Obj
$sessionId
= $O.sessionId

$Obj
= @{url = 'https://google.com'} | ConvertTo-Json
$O
= Invoke-RestMethod -Uri http://Win10:17556/session/$sessionId/url -Method Post -Body $Obj

$O
= Invoke-RestMethod -Uri http://Win10:17556/session/$sessionId/window -Method DELETE

Can I somehow expose remote connection ability of the browser-specific driver classes?
Or use the RemoteWebDriver class to connect directly to the MicrosoftWebDriver without the WebDriver "node" + "hub" overhead?

Thank you

Jim Evans

unread,
Mar 30, 2016, 2:21:56 PM3/30/16
to Selenium Users
If there are no problems executing wire protocol commands to a remote instance of MicrosoftWebDriver
.exe, then yes, you can use RemoteWebDriver directly with it. However, be aware that the W3C WebDriver specification states that a terminal node (which MicrosoftWebDriver.exe is) should only accept local connections, so when the executable becomes spec compliant, that will no longer work, and you'll need the Java server. Note carefully that you don't need to use a hub and node; a single instance of the standalone server would do.

ili

unread,
Mar 31, 2016, 8:41:47 AM3/31/16
to Selenium Users
Thank you for all the help

It's working now, I'm using the RemoteWebDriver to connect directly to the MicrosoftWebDriver.exe.
Note that the MicrosoftWebDriver.exe do not allow remote execution by default you need to enable it with the --host=XXX switch
illy
Reply all
Reply to author
Forward
0 new messages