How do you set the port for ChromeDriver in Selenium?
Asked Answered
P

2

5

As some background, I'm playing around with BrowserMob proxy and I am getting blocked by the port settings. So I'd like to know how to set a port by myself.

 Server srv = new Server(@"C:\BMob\browsermob\bin\browsermob-proxy.bat");
 srv.Start();
 Client cln = srv.CreateProxy();
 cln.NewHar("BOWZA"); 
 ChromeOptions co = new ChromeOptions();
 Proxy  seleniumProxy = new Proxy { HttpProxy = cln.SeleniumProxy };
 co.Proxy = seleniumProxy;
 ChromeDriver cDriver = new ChromeDriver(co);
// What do I do now...?

I just failed to find anything documenting this, sorry

Pronouncement answered 8/7, 2016 at 15:22 Comment(1)
Know this is old but where does Server and Client come from as in Visual Studio it the namespace can't be found. Any reference I add seems incorrect. Like the server.Stop() objective isn't found but the Start is in theory.Blackpool
K
6

This should work:

ChromeDriverService service= ChromeDriverService.CreateDefaultService(DRIVER_PATH);
service.Port = <PORT>;
IWebDriver WebDriver = new ChromeDriver(service);
Kimmie answered 8/7, 2016 at 15:57 Comment(0)
M
0

This works for me. I'm using webDriverManager as well

    ChromeDriverService chromeDriverService = new ChromeDriverService.Builder().usingPort(DesiredPortNumber).build();

Then use it as a parameter when initializing new driver

new ChromeDriver(chromeDriverService , BrowserOptionsManager.getChromeOptions());
Monumentalize answered 3/1, 2022 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.