It is important to remember that the stock price in principle reflects the value of the company, so the market cap should drop upon issuance of the the dividend.
However, the above reasoning neglects to consider taxes, which make the question a bit more interesting.
The key fact is that different investors are going to get taxed on the dividend to varying degrees, ranging from 20% for qualified dividends in the USA for a high-income individual in a taxable account (and even worse for non-qualified dividends) to 0% for tax-exempt nonprofits, retirement accounts, and low-income individuals.
The high-tax investors are going to be a bit averse to paying tax on that dividend, whereas the tax-free investors are not. Hence in a tax-rational market the tax-free investors are going to be the ones buying right before a dividend and the tax-paying investors will be buying right afterwards. Tax-exempt investors could in principle make some amount of money buying dividends to keep them off the tax-paying investors' books. (Of course, the strategy could backfire if too many people did it all at once.)
That said, the tax-payers have the tax disincentive to prevent them from fully exploiting the opposite strategy of selling just before a dividend. In particular, they are subject to capital gains tax when they sell at a profit (unless they have enough compensating capital losses), and it is to their after-tax profit to defer taxation by not trading.
That said, the stock market has well-known irrationality when it comes to considering tax consequences, so logic based on assumed rationality of the market does not always apply to the extent one would expect.
The foremost example of tax-irrationality is the so-called "dividend paradox", which basically states that corporations should favor stock buybacks (or perhaps loan repayment) to the complete exclusion of dividends because capital gains are taxed less harshly than dividends in a variety of ways, some of which are subtle:
1) Historically (although not currently in the USA for qualified dividends) the tax rate was higher for dividends. (In Canada, for example, dividends are taxed at twice the rate of capital gains.)
2) If you die holding appreciated stock then you (meaning your heirs) completely escape US the capital gains tax on the accrual during your lifetime.
3) Capital gains tax can be deferred by simply not selling. In comparison to dividends, this is roughly equivalent to getting a tax-free loan from the government which is invested for profit and paid at a later date after inflation has eaten away at the real value of the loan. For example, if all your stock investments increase by 10%/year but you sell every year, in a high-tax bracket situation you're total after-tax return will be only 8% per year. In contrast, if you hold the same investments for many many years and then sell, your total return will be nearly 10% per year, because you only pay 20% once (at the end).
4) A capital gain can often be neutralized by a capital loss in another stock, so that no tax results. If you loose money on a stock that is paying dividends, you're still going to have to pay tax on that dividend. There are companies that borrow money to pay out that taxable-dividend each quarter, which seems like gross tax malpractice on the part of the CFO.
(If the dividend paradox doesn't make sense, first consider the case that you owned ALL the shares of a company. It wouldn't matter to you at all on a pre-tax basis whether you got a $1000 company buyback or a $1000 dividend, because after the buyback/dividend you'd still own the entire company and $1000. The number of shares would be reduced, but objecting that you owned fewer shares after the buyback would be like saying you have become shorter if your height is measured in inches rather than centimeters.)
[Of course, in the case of many shareholders you can get burned by failing to sell into the buyback when the share price is too high, but that is another matter.]