I have a list of Anchor tags. I want to click on each tag , scrap the page's title and print each item. However it returns error after the second item.
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "D:\\ronjg\\Desktop\\DEV - LANG\\chromewebdriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://petstore.octoperf.com/actions/Catalog.action");
List<WebElement> myList=driver.findElements(By.id("SidebarContent"));
for (WebElement element : myList) {
List<WebElement> listofAtags = element.findElements(By.tagName("a"));
int size_of_links = listofAtags.size();
System.out.println(size_of_links);
for (WebElement lnk : listofAtags) {
lnk.click();
String res = driver.findElement(By.xpath("/html/body/div[2]/div[2]/h2")).getText();
System.out.println(res);
WebElement reutrn_home = driver.findElement(By.xpath("//*[@id=\"BackLink\"]/a"));
reutrn_home.click();
}
}
driver.close();
}}
The Links of the group are : Fish, Dogs, Cats, Reptiles, Birds . So I want to to print each item , so the end print out would be like this : Fish Dogs Cats Reptiles Birds