In addition to putting in the time and distance required to train for an open water swim or triathlon, you need to prepare for the time when the black line at the bottom disappears.
One way to do this, is to find a lap without other swimmers (or at least they should be on the same page as you). Then try to close your eyes every time your head is underwater, and open them when you breathe. If you want to gauge the distance to the end, do it using your orientation technique, and look for the starting block or your water bottle.
Start out with doing it just in the middle of the pool, and as you get better, you can do it for (almost) the whole lap.
This drill will let you focus on swimming straight (you might have an encounter or two with the lane line to begin with), and to relax even if you can’t see what’s below you.