Selenium GeckoDriver get IP and Port no of the launched driver instance

最后都变了- 提交于 2019-12-25 15:52:50

问题


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.


回答1:


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());


来源:https://stackoverflow.com/questions/44905865/selenium-geckodriver-get-ip-and-port-no-of-the-launched-driver-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!