How can we get the userAgent of a browser when running automated tests?

When performing automated tests, how can we acquire the browser’s userAgent?

Hi Ian,

You can get the userAgent by running this command: navigator.userAgent along with Javascript Executor

Here is a sample you can refer to:

print(driver.execute_script("return navigator.userAgent"))