Selenium Webdriver – Get SessionID from a Web Application

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

3 thoughts on “Selenium Webdriver – Get SessionID from a Web Application

  1. Pingback: SELENIUM TO REST-ASSURED ADAPTER – Keep Software Testing Weird

  2. Pingback: SoapUI Get SessionID | Keep Software Testing Weird

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s