Session not found exception | Selenium Forum
M
Posted on 20/01/2016
Am getting session not found exception:

Am getting exception:
org.openqa.selenium.WebDriverException: Session not found: 23def0a1-dd11-4f79-b562-e48503831d77
Command duration or timeout: 16 milliseconds
---------------------------------------------------------------------------------------------------------------

following is my code:

package p1;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class google_c {
static WebElement box2;
static List<WebElement> links2;
static ProfilesIni prof = new ProfilesIni();
static FirefoxProfile p = prof.getProfile("Chaitra");


static WebDriver w=new FirefoxDriver(p);
public static void main(String[] args) {
// TODO Auto-generated method stub






w.get("https://www.google.com");
w.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
w.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
w.manage().window().maximize();
w.findElement(By.name("q")).sendKeys("types of kindles");
w.findElement(By.name("q")).sendKeys(Keys.ENTER);
//==========print links==1st page=========================

WebElement box=w.findElement(By.xpath("//*[@id='ires']"));
List<WebElement> links = w.findElements(By.xpath(".//*[@id='rso']/div/div/div/div/div/div/cite"));
System.out.println("Total links -> "+ links.size());
for(int i=0;i<links.size();i++)
System.out.println(links.get(i).getText());


//--------------click on every link of 1st page---------------------------

for(int i=0;i<links.size();i++)
{

try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println(links.get(i).getText());
w.navigate().to(links.get(i).getText());
w.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
if(w.getPageSource().contains("Page Not Found"))
{
System.out.println("following link is broken"+links.get(i).getText());
w.navigate().back();
w=new FirefoxDriver();
}
else

{
//System.out.println("following link is workin fine"+links.get(i).getText());
w.navigate().back();
w.close();
w=new FirefoxDriver();
}

try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("clicked"+i+"th link");
}
}}

M
Replied on 22/01/2016

[quote:1vi81xuk]{
//System.out.println("following link is workin fine"+links.get(i).getText());
w.navigate().back();
w.close();
w=new FirefoxDriver();
}[/quote:1vi81xuk]

don't close firefox browser.