Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 548
sjr Avatar asked May 23 '12 21:05

sjr


1 Answers

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

((RemoteWebDriver) driver).getSessionId()
like image 128
shex Avatar answered Sep 21 '22 21:09

shex