java - Get cookies from selenium session -
i want session variable , cookies after login. have used selenium webdriver , login. how session , cookies after login in selenium.here code:
try { webdriver driver = new firefoxdriver(); driver.get("https://pacer.login.uscourts.gov/csologin/login.jsf"); system.out.println("the title is"+driver.gettitle()); webelement id= driver.findelement(by.xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/table[1]/tbody/tr/td[2]/input")); webelement pass=driver.findelement(by.xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/table[2]/tbody/tr/td[2]/input")); webelement button=driver.findelement(by.xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/div[2]/button[1]")); id.sendkeys("username"); pass.sendkeys("password"); button.click(); } catch (exception e) { e.printstacktrace(); }
please provide suggestion asap.
thanks
i ran code following code additions , able following value in console.
try { webdriver driver = new firefoxdriver(); driver.get("https://pacer.login.uscourts.gov/csologin/login.jsf"); system.out.println("the title is" + driver.gettitle()); webelement id = driver .findelement(by .xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/table[1]/tbody/tr/td[2]/input")); webelement pass = driver .findelement(by .xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/table[2]/tbody/tr/td[2]/input")); webelement button = driver .findelement(by .xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/div[2]/button[1]")); id.sendkeys("username"); pass.sendkeys("password"); button.click(); thread.sleep(10000); set<cookie> cookies = driver.manage().getcookies(); system.out.println("size: " + cookies.size()); iterator<cookie> itr = cookies.iterator(); while (itr.hasnext()) { cookie cookie = itr.next(); system.out.println(cookie.getname() + "\n" + cookie.getpath() + "\n" + cookie.getdomain() + "\n" + cookie.getvalue() + "\n" + cookie.getexpiry()); } } catch (exception e) { e.printstacktrace(); }
console
the title ispacer login
size: 1
jsessionid
/csologin/
pacer.login.uscourts.gov
e44c8*********************400602
null
instead of thread.sleep(10000) can try using explicit wait. believe web page took time set cookies since busy waiting page load.
hope helps you.
Comments
Post a Comment