Hi
I wan to save all the detected elements of a web page in a file . i
was trying the following example but getting following error.
Caused by: java.io.NotSerializableException:
org.openqa.selenium.firefox.FirefoxWebElement
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
any one any idea how to solve it..
TheCode.
=======================
public class Selenium1Example {
public static void main(String[] args) {
System.out.println("Initiation Starts");
WebDriver driver = new FirefoxDriver();
String baseUrl = "
http://www.ltu.se";
driver.get("
http://www.ltu.se");
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
selenium.open("
http://www.ltu.se");
selenium.waitForPageToLoad("90000");
// Get the underlying WebDriver implementation back. This will refer
to the
// same WebDriver instance as the "driver" variable above.
String s ="C:\\object.txt";
FileOutputStream fos = null;
ObjectOutputStream outObject = null;
try
{
fos = new FileOutputStream(s);
outObject = new ObjectOutputStream(fos);
//out.writeObject(time);
//out.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
elementSerialized es1;
List<WebElement> allOptions = driver.findElements(By.tagName("a"));
for (WebElement option : allOptions)
{
es1 =new elementSerialized(option);
try
{
outObject.writeObject(es1);
}
catch(Exception e)
{
e.printStackTrace();
}
break;
}
try
{
outObject.close();
}
catch(Exception e)
{
e.printStackTrace();
}
//Finally, close the browser. Call stop on the
WebDriverBackedSelenium instance
//instead of calling driver.quit(). Otherwise, the JVM will
continue running after
//the browser has been closed.
//selenium.stop();
WebElement e2=null;
elementSerialized es2=null;
FileInputStream fis = null;
ObjectInputStream in = null;
try
{
fis = new FileInputStream(s);
in = new ObjectInputStream(fis);
es2 = (elementSerialized)in.readObject();
e2=es2.getWebElement();
in.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
}
}
public class elementSerialized implements Serializable
{
private WebElement element;
public elementSerialized(WebElement e1)
{
element=e1;
}
public void setElement(WebElement e1)
{
element=e1;
}
public WebElement getWebElement()
{
return element;
}
}