问题描述
我正在使用Selenium 3.4,Geckodriver 0.17.
我使用以下代码启动FirefoxDriver
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());
有没有办法获取启动的驱动程序实例的IP和端口?
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
输出的第一行 127.0.0.1:38840 打印我想要的信息.我不想解析日志,因为我将并行运行驱动程序.
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.
推荐答案
RemoteWebDriver具有 getCommandExecutor
方法.
The RemoteWebDriver has getCommandExecutor
method.
可以类型转换为HttpCommandExecutor
和 getAddressOfRemoteServer()
方法返回URL.
Which can be TypeCasted to HttpCommandExecutor
and getAddressOfRemoteServer()
method returns the URL.
HttpCommandExecutor ce = (HttpCommandExecutor) driver.getCommandExecutor();
System.out.println(ce.getAddressOfRemoteServer());
这篇关于Selenium GeckoDriver获取启动的驱动程序实例的IP和端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!