selenium - Getting java.lang.ClassCastException while trying to access element in the list -
sample code:
public class { list<webelement> itemlist = new arraylist<webelement>(); public list<webelement> getitemslist() { itemlist = (driver.findelements(by.xpath("<some valid xpath>"))); return(itemlist); } } public class b { hp = new a(); public void subscribe() { hp.getitemslist().get(0).click(); } }
i creating list of webelements on page in class , in class b trying click on first element.
on execution getting below exception:
> java.lang.classcastexception: java.lang.stackoverflowerror cannot cast java.lang.exception
issues has thing findelements because when added elements using findelement method list manually in code, code working fine.
in below example have commented findelements line , instead added elements manually, code working fine.
public class { list<webelement> itemlist = new arraylist<webelement>(); public list<webelement> getitemslist() { //itemlist = (driver.findelements(by.xpath(".//*[@id='hc6|stocks|item1']/span[2]""))); itemlist.add(driver.findelement(by.xpath(".//*[@id='hc6|stocks|item1']/span[2]"))); itemlist.add(driver.findelement(by.xpath(".//*[@id='hc6|stocks|item2']/span[2]"))); itemlist.add(driver.findelement(by.xpath(".//*[@id='hc6|stocks|item3']/span[2]"))); return(itemlist); } }
can suggests whats going wrong?
i tried xpath follows:
list<webelement> itemlist = driver.findelements(by.xpath(".//*[@class='itemrow button']/span[2]")); // .//*[@class='itemrow button']/span[2] system.out.println("list " + itemlist);
returned following elements:
list [[[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]], [[chromedriver: chrome on xp (a92615f2a2338af92c3dc57ff2366bf8)] -> xpath: .//*[@class='itemrow button']/span[2]]]
i hope not problem xpath or findelements method. using framework writing tests?
in line:
//itemlist = (driver.findelements(by.xpath(".//*[@id='hc6|stocks|item1']/span[2]"")));
observed additional double quotes present @ end of xpath span[2]""
. check if reason error.
java.lang.stackoverflowerror occurs in case of recursive calls made. please code whether recursion happening.
java.lang.classcastexception: java.lang.stackoverflowerror cannot cast java.lang.exception
in catch block, used exception
, code throws stackoverflowerror
error (but not exception)
go through code thoroughly find out recursion happening.
Comments
Post a Comment