In this study, eight pharmaceuticals belonging to two classes, antihistaminic and antimigraine, were considered. Ultra‐performance liquid chromatography‐diode array detection was set up and gradient elution was used. The mobile phase was composed of acetonitrile and trifluoroacetic acid solution. Chromatographic separation was carried out with a run time of 9 min. The preconcentration of eight studied solutes was realized by micro solid‐phase extraction. Multiwalled carbon nanotubes, cetyltrimethylammonium bromide‐titanium dioxide nanotubes, and C‐18 bonded silica solid‐phase extraction (SPE) sorbents were evaluated and compared concerning recoveries. The results of the optimization of factors affecting the extraction efficiency including sample volume, the elution solvent type, and its volume are reported. For validation of the analytical procedure, specificity, linearity, precision, accuracy, limit of detection, and limit of quantification were evaluated. The developed method was successfully applied to the analysis of wastewater treatment samples. The extraction recoveries of pharmaceutical substances were above 81.23% for the three SPE sorbents. The extraction method was selective and the detection and quantification limits were between 0.004–0.02 and 0.01–0.06 μg/L, respectively. All the results indicated the potential application of the three studied SPE sorbents for the extraction of selected pharmaceuticals from wastewater.