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(); } } }
Pingback: SELENIUM TO REST-ASSURED ADAPTER – Keep Software Testing Weird
Pingback: SoapUI Get SessionID | Keep Software Testing Weird
Thanks for finally writing about >Selenium Webdriver
– Get SessionID from a Web Application | Keep Software
Testing Weird <Liked it!
LikeLike