This might seem like a difficult question to answer because most of the time home sellers won’t sell unless they’re sure you can secure financing and lenders won’t process a mortgage application until they know what you’re buying. However, the answer is simple: get pre-approved for a mortgage.
All preapproval entails is having a lender evaluate basic factors like your credit score, income, and debts to determine how much money they’d be willing to lend you, if any. This is merely a preliminary check to verify that you are an eligible borrower and does not take into account the specifics of any potential loan offer. You are not bound to accept a loan from the company that gave you pre-approval and do not need to shop around at this stage; you are basically just reassuring the seller about the state of your financials.
Preapproval also gives you a pretty good sense of what kind of home you can afford, and with it you can move on to house hunting. Once you find the property of your dreams and have a signed contract outlining the terms of the sale, you can shop around for the lowest mortgage rates.
So, to answer the original question, you should find your home before shopping for a mortgage, but before you do either one, get pre-approved.