0

I'm using Selenium 3.4, Geckodriver 0.17.
I launch FirefoxDriver using the below code

    System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
    FirefoxDriver driver = new FirefoxDriver();
    driver.get("http://www.bing.com");
    System.out.println(driver.getSessionId());

Is there a way I can get the IP and the port of the launched driver instance?

The data I want is printed in the logs.

1499170600204   geckodriver INFO    Listening on 127.0.0.1:38840
1499170601127   geckodriver::marionette INFO    Starting browser C:\Program Files\Mozilla Firefox\firefox.exe with args ["-marionette"]
[GFX1]: Potential driver version mismatch ignored due to missing DLLs igd10umd32 v= and igd10iumd32 v=
1499170608388   Marionette  INFO    Listening on port 12793
Jul 04, 2017 5:46:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C

The First line of the output 127.0.0.1:38840 prints the info I want. I don't want to parse the log as I will be running drivers in parallel.

Madhan
  • 5,750
  • 4
  • 28
  • 61

1 Answers1

0

The RemoteWebDriver has getCommandExecutor method.

Which can be TypeCasted to HttpCommandExecutor and getAddressOfRemoteServer() method returns the URL.

HttpCommandExecutor ce = (HttpCommandExecutor) driver.getCommandExecutor();
System.out.println(ce.getAddressOfRemoteServer());
Madhan
  • 5,750
  • 4
  • 28
  • 61