In many practical instances, price elasticity of demand (PED) is calculated in a back of the envelope fashion, just as taught in the textbooks! Firms can adjust their price by some small amount and observe the demand response. For relatively small changes in price and quantity, little accuracy is lost by assuming that the demand function is locally linear, so that the change in price and demand jointly give an estimate for $$\frac{dQ}{dp}.$$ Since $p$ and $Q$ are already known, this is enough to calculate the PED:
$$\eta=\frac{dQ}{dp}\frac{p}{Q}.$$
This method yields only a point estimate of elasticity at the current price. However, one can get an incredibly long way with just this estimate thanks to the so-called Lerner condition: that a firm with marginal cost $c$ facing a price elasticity of $\eta$ maximises profit when $$\frac{p-c}{p}=-\frac{1}{\eta}.$$ Once the price elasticity of demand is estimated in the above fashion, this formula can be used to infer if the firm's price is above or below its profit-maximising level (allowing a firm to correct towards that level). Alternatively, this kind of analysis is often used as a heuristic in competition policy (antitrust) because, by estimating the right hand side of the Lerner formula, competition authorities can get an estimate for the left hand side (i.e. for how much power the firm has to price above marginal cost).
One drawback of this approach is that, at least in its simplest implementation, it does not control for factors such as how a change in the price of a product affects the demand of other products sold by the same firm (and thus overall profit).
You can see a nice informal discussion of Amazon's book pricing based on this kind of back of the envelope work here.
For more formal purposes, and when data is readily available, the process is often similar but slightly more careful in the estimation of demand. An excellent example of this kind of work can be found in Ellison & Ellison's 2009 Econometrica Paper, Search, Obfuscation, and Price Elasticities on the Internet. They proceed by estimating the firm's demand function econometrically (rather than via the heuristic method described above), and then calculate the implied PED from this estimated demand. Using an equation analogous to the Lerner condition, they are able to infer how far from the competitive case the market is, and attribute this discrepancy to search obfuscation.
In practice, for economists working outside of a firm, the main difficulty is often obtaining the data necessary to estimate the PED (Ellison & Ellison had excellent data thanks to collaboration with a firm in the market).