In 1846, Cooper was assigned to the schooner of the Home Squadron, and in March of that year "Flirt" reported for duty under U.S. Army Brigadier General (later major general) Zachary Taylor in the Mexican War. Cooper commanded a detachment of men at Port Isabel, Texas, in operations related to the Siege of Fort Texas of early May 1846, and remained with Taylor's force until the capture of Monterrey, Mexico, in September 1846. "Flirt" then was reassigned to Commodore David Conner's squadron off Veracruz, Mexico, and aboard her Cooper took part in the First Battle of Tabasco in October 1846, an attack on Alvarado, attacks on Tuxpan, and the Second Battle of Tabasco in June 1847. After the American capture of Mexico City in September 1847, "Flirt" detached from Conner's squadron and returned to the United States.