So, given that there's basically zero delay between those two actions in your code, can you see the problem? There is obviously no such link in the current page because the page containing that link hasn't loaded yet, because you haven't waited for it to load.