Since WebDriver tries to simulate real users, it cannot interact with elements which are invisible/hidden.
There can be so many reason for this. solve this using different ways.
1- Using WebdriverWait that is also know as explicit wait
2- Using unique xpath- using xpath ways.
3- Get the size of element then click or perform any action on first one.
And one more doubt in this Will this program extract the Link(s) who have tag name "span" as you explained(I wrote the same.)? Because I have written here from "List<WebElement>allLinks= driver.findElements(By.tagName("a"))". I am a bit confused that here I have written code for links who have tag name "a" but I am expecting it will extract the link(s) who have tag name "span" also.Will it work?
if you want to extract span use tagname("span");
tagname("a"); will extract all hyperlink and nothing else(so no span tags).