- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get userAgent information in Selenium Web driver?
We can get the user Agent information with Selenium webdriver. This is done with the help of the JavaScript Executor. Selenium executes JavaScript commands with the help of the execute_script method.
To obtain the user Agent information, we have to pass the return navigator.userAgent parameter to the execute_script method. Selenium does have a direct method the to get or modify user Agent.
Syntax
a= driver.execute_script("return navigator.userAgent") print(a)
Example
from selenium import webdriver from selenium.webdriver.chrome.options import Options #object of Options class op = webdriver.ChromeOptions() #set chromedriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", options=op) #maximize browser driver.maximize_window() #launch URL driver.get("https://www.seleniumhq.org/download/"); #get user Agent with execute_script a= driver.execute_script("return navigator.userAgent") print("User agent:") print(a) #close browser session driver.quit()
Output
- Related Articles
- How to get text with selenium web driver in python?
- Get text using selenium web driver in python?
- What is selenium web driver?
- What is Web Driver in Selenium?
- How to run selenium (Firefox) web driver without a GUI?
- Difference between selenium RC and Web Driver?
- What is the Selenium Web Driver Architecture?
- How to use Selenium Web Driver and JavaScript to Login any website?
- How to get innerHTML of whole page in selenium driver?
- Using Selenium Web Driver to retrieve value of a HTML input.
- How to change user agent for Selenium driver?
- Which programming language is better for writing Selenium web driver scripts, Python or Java?
- How to setup Chrome driver with Selenium on MacOS?
- How to handle web based alerts in Selenium?
- What is Selenium Internet Explorer Driver or IE Driver?

Advertisements