Shark scales found by researchers are roughly 420 million years old. Fossil trees from an ancient forest in England are about 390 million years old.
So shark ancestors were already in the water before the oldest forests we have found appeared on land. Those were not today's shark species. The shark family kept changing, and many ancient kinds died out.