Ultrasonic transducers have demonstrated the ability to effectively excite guided waves that can propagate over long distances and are thus employed in monitoring systems. An ultrasonic piezoelectric transducer that strongly excites a mode travelling in the web of the rail is required to detect cracks in the rail web. A numerical method referred to as the Coupled Semi-Analytical Finite Element - 3 Dimensional Finite Element (Coupled SAFE-3DFE) method is employed to model the excitation of guided waves in a rail by a transducer. The aim of this study is to demonstrate that the Coupled SAFE-3DFE method used in conjunction with mathematical optimization methods, can automate the optimal design of a transducer. The optimal transducer was constructed and experimental measurements were found to agree with the predicted performance.