Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get session_id of active driver opened with Selenium and Appium if several drivers were activated?

While automating I open several browsers, say Firefox, with

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

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)?

like image 939
Andriy Avatar asked Apr 07 '16 12:04

Andriy


People also ask

Can we use Selenium WebDriver and Appium WebDriver in the same code?

Is it possible to use appium and selenium together in one test case? yes you can, no need to switch the context, use the web/mobile driver as your test case flow goes.

Can Selenium interact with already opened browser?

Mastering XPath and CSS Selector for SeleniumWe can interact with an existing browser session. This is performed by using the Capabilities and ChromeOptions classes. The Capabilities class obtains the browser capabilities with the help of the getCapabilities method.

Can Selenium work on multiple tabs?

Just like you might open web pages in different tabs locally, it's also possible to have multiple tabs up in one browser during a Selenium test.


2 Answers

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

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());
like image 86
Florent B. Avatar answered Oct 22 '22 18:10

Florent B.


((ChromeDriver)driver).sessionId();

like image 37
Sonali Das Avatar answered Oct 22 '22 18:10

Sonali Das