RE: Webdriver session is closed while test is running and “SessionNotFoundException: no such session” exception is published.

I am trying to run a test in infinite loop using for(;;). The test is running but after couple of cycles, the chrome session is getting closed and the mentioned exception is published. I am pasting my code below.

public void opn_dshBrd_Itm() throws Exception
{

for(;;)
{
Thread.sleep(2000);
// Click on Dashboards link
PGO_keyNoteApp.lnk_Dashboards(driver).click();
Thread.sleep(3000);
String pg_title = driver.getTitle();
System.out.println(pg_title);
// Get Measurements count
int cnt_Msrmnt = 0;
cnt_Msrmnt = PGO_keyNoteApp.txt_ele_msrmnts(driver);
System.out.println(cnt_Msrmnt);
JavascriptExecutor je = (JavascriptExecutor) driver;
WebElement nw_wnd_lnk = null;
Actions newwin = new Actions(driver);
String winHandleBefore = driver.getWindowHandle();
String windw_ttl = null;
// Open and close all the links
for (int i =1; i<=cnt_Msrmnt; i++)
{
// scrolldown to view the nw_wnd_lnk webelement
je.executeScript(“window.scrollBy(0,21)”);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// get each link for 1hr timeframe
nw_wnd_lnk = PGO_keyNoteApp.lnk_avlblty_1hr(driver, i);
// Click and open the 1 hr link in new window
while(nw_wnd_lnk.isDisplayed() && nw_wnd_lnk.isEnabled())
// {
driver.manage().timeouts().pageLoadTimeout(300, TimeUnit.SECONDS);
newwin.sendKeys(Keys.SHIFT).click(nw_wnd_lnk).keyUp(Keys.SHIFT).build().perform();
System.out.println(i);

// Switch to the new window opened for 1hr link
for (String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
Thread.sleep(5000);
windw_ttl = driver.getTitle();
System.out.println(windw_ttl);

}
// Close the new window opened
driver.close();

Thread.sleep(2000);
driver.switchTo().window(winHandleBefore);
break;
// }

}

Add Comment
2 Answers

What is the “PGO_keyNoteApp” in your code? better you provide web URL if possible?

Default Answered on October 19, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.