What is it that your code does? If it finds the name of the country in the url, it clicks on a link, but what does that link do? I only ask because there might be an easier way depending on what you’re trying to achieve.
when you click onto the search page from a country page the code automatically picks up the country from the last URL then automatically selects that country from the drop down option link list, rather than you manually selecting it once on the search page. I’ve got a whole load of countries to add, but I’ve noticed that it may need an on load first because although the country is now selected it has not changed the search results from the default provision…!!
It sounds like you might be better off passing the country in the URL (e.g. example.com/search?country=Belgium). That way you can render the page with the correct results without needing any JS, and it would also allow the user to bookmark the link and come back to it later.