Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user agent information in Selenium WebDriver with Python

I am trying to get the actual user agent that I am using in Selenium, at the moment with the chromedriver.

I found a Java version of this problem: How to get userAgent information in Selenium Web driver.

Does someone know how to do that in Python?

like image 446
bkemmer Avatar asked Jul 23 '18 15:07

bkemmer


People also ask

What is User Agent in selenium Python?

The user Agent header has a particular string that provides the network protocol along with the details of operating system, software version, application, and so on. Selenium does have the ability to get or modify user Agent. This is done with the help of the JavaScript Executor.

What is user agent used for in selenium?

Conclusion – Selenium User-Agent In user agent is the important one and it is the way for interacting with the web servers to determine how we are accessing the browsers that can be used on the performance. Generally, it acts as String, boolean, Number are the types to create the user preference type.

How do I commit in selenium?

Navigate to Team => Commit. #7) Right-click on the Selenium automation project and navigate to Team => Add to Index. #8) Enter the commit message and click on the Commit button. This will add all your Test Cases files to staged changes.


1 Answers

The same manner as inside your link:

user_agent = driver.execute_script("return navigator.userAgent;")

PS: Using execute_script method you can run JS inside your driver.

Hope it helps you!

like image 196
Ratmir Asanov Avatar answered Sep 19 '22 00:09

Ratmir Asanov