I don't know why this error shows up . Need help to fix it . Website i am working on :"http://freevideolectures.com/Course/3680/Pentaho-BI" . In this site
List<WebElement> cl = d.findElements(By.xpath("//ul[@class='lecture_menu']/li/a"));
System.out.println(cl.size());
for(int e=0 ; e<=cl.size()-1; e++) {
cl.get(e).click();// i think the error shows up here, the loop runs for e=0 ,
Thread.sleep(1000);
String q = d.findElement(By.xpath(".//*[@id='cs-about']/div/div[2]/div[2]/span/a")).getAttribute("href");
System.out.println(q);
}
The loop runs once for e=0 , i am getting the output for that . After this the error shows up . error: stale element reference: element is not attached to the page document. Help Please .
Just break the loop when you find the element you want to click on it.
Reason is it is finding element even though that element is clicked. Use For -If Loop so when you get that element break it
Here is the sample code which opens the
WebBrowser
withURL
ashttp://freevideolectures.com/Course/3680/Pentaho-BI
, browses through all the linksBy.xpath("//ul[@class='lecture_menu']/li/a")
, opens each of them in a newTab
prints thehref
and closes theTab
:The Output on my Console is :