如果激活了多个驱动程序,是否可以获取使用 Selenium 和 Appium 打开的活动驱动程序的 session_id? [英] Is it possible to get session_id of active driver opened with Selenium and Appium if several drivers were activated?

查看:23
本文介绍了如果激活了多个驱动程序,是否可以获取使用 Selenium 和 Appium 打开的活动驱动程序的 session_id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在自动化时,我打开了几个浏览器,比如 Firefox,

While automating I open several browsers, say Firefox, with

driver1 = webdriver.Firefox()
driver2 = webdriver.Firefox()
driver3 = webdriver.Firefox()
.....

有没有办法获取活动浏览器的 session_id 和 webdriver 本身?Appium 也有同样的问题.是否可以获取活动设备(虚拟或真实)的 session_id 和驱动程序本身?

Is there a way to get the session_id and webdriver itself of the active Browser? The same question for Appium. Is it possible to get session_id and driver itself of the active device (virtual or real)?

推荐答案

使用 Selenium/Java 获取驱动程序会话 ID:

To get the driver session id with Selenium / Java:

WebDriver driver = new FirefoxDriver();

SessionId session = ((FirefoxDriver)driver).getSessionId();
System.out.println("Session id: " + session.toString());

使用 Selenium/Java 获取远程驱动程序会话 ID:

To get the remote driver session id with Selenium / Java:

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4722/wd/hub"), capabilities);

SessionId session = ((RemoteWebDriver)driver).getSessionId();
System.out.println("Session id: " + session.toString());

这篇关于如果激活了多个驱动程序,是否可以获取使用 Selenium 和 Appium 打开的活动驱动程序的 session_id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆