About drug discovery: How do they know what a non-existent substance will do?

"Hello, I have a question related to drug design. For instance, we can learn what an active molecule obtained from a plant does by experimenting with it in various disease models, or we can evaluate its drug potential through computer-based studies like docking.

But what I'm curious about is how they synthesize a molecule that doesn't exist yet. Let's take Fluoxetine as an example. How does a chemist say, 'I'm going to synthesize a molecule that will be a serotonin reuptake inhibitor,' and then design the Fluoxetine molecule from scratch, knowing it will work? How can a molecule be designed for a specific purpose when there is no physical molecule present? In other words, if they are using Computer-Aided Drug Design - CADD for this, shouldn't designing all possible serotonin reuptake inhibitors be a matter of just a few clicks and a few weeks?

Another example is the scientists who discovered alprazolam. Where did they start, and how did they know how to synthesize a molecule that would alleviate anxiety?

Or, like in the discovery of active compounds, do they synthesize a speculative molecule and then test whether it works for a particular purpose through trial and error? Thank you in advance for your answers."