Getting SessionID/Cookies from a Web Application using Selenium
package com.test; import java.util.concurrent.TimeUnit; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; public class GetSession { public static void main(String args[]) throws InterruptedException { WebDriver driver = new FirefoxDriver(); try { String domainString = "http://yourURL"; String baseUrl = domainString; driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS); driver.get(baseUrl + "/Login.aspx/"); driver.findElement(By.id("username")).clear(); driver.findElement(By.id("username")).sendKeys("username"); driver.findElement(By.id("password")).clear(); driver.findElement(By.id("password")).sendKeys("password"); driver.findElement(By.cssSelector("input.primary.btn")).click(); String ASPNET_SessionId = driver.manage().getCookieNamed("ASP.NET_SessionId").toString(); System.out.println(ASPNET_SessionId); } finally { driver.close(); } } }