Lebanon has elected a new president after multiple failed attempts had left the country without a head of state since 2022.