Mechanism of electrocatalytic and photo-electrocatalytic reactions by in operando X-Ray absorption spectroscopy