Eureka!"s like the one Archimedes had when he stepped in a bathtub and suddenly realized the answer to the problem of testing metals' density are few and far between, and mostly it's just trying and failing and trying something else, feeding in data and eliminating variables and staring at the results, trying to figure out where you went wrong.
We tend to think of imagination and foresight like we are prone to think of life (sometimes) -- as an inscrutable flash of something from the outside that magically takes us over some large boundary in one atomic step. We even call it a flash (of insight), a eureka moment, a light bulb in our heads that suddenly turns on. But if you reflect on this phenomenon for a moment, you know you don't go suddenly from a blank mind to a fully formed solution. You were already thinking about the problem, and other near solutions that don't work, when suddenly you see a new connection that enables you to reuse familiar things on a novel way. Insight comes in small increments, leveraging what was already there.