sjr
sjr

Reputation: 156

How to get browser sessionId using Selenium webdriver

I'm using selenium webdriver (php-webdriver-bindings Yii extension) and I'm trying to get the browser sessionId (the one that the test will be using). I thought I could get this through webdriver, but that doesn't seem to be the case. Webdriver has a sessionId, but that is not the one the test browser is using.

I'm trying to login prior to the test running to allow my tests to be an authenticated user which will allow them to access the pages I'm testing.

I've been researching and testing this for a few days now and I'm at a loss. Any help would be greatly appreciated.

Thanks.

Upvotes: 5

Views: 14211

Answers (2)

Steve HHH
Steve HHH

Reputation: 13147

I had this problem in Java, but on closer examination of the source code, noticed that the driver I was using was instantiated as a WebDriver object. After changing it to a RemoteWebDriver object, the .getSessionId() method was exposed, and driver.getSessionId() returned the session id as expected.

I'm not sure how that would translate to PHP, but I'd recommend going back and checking to ensure that your driver is a RemoteWebDriver object, rather than a WebDriver object.

Upvotes: 0

shex
shex

Reputation: 346

You can cast to a concrete type, e.g. RemoteWebDriver, which they all inherit from, and also implements getSessionId:

((RemoteWebDriver) driver).getSessionId()

Upvotes: 5

Related Questions