Hi all, in this post I will show how to change user agent for your test automation projects by using User-Agent Switcher add-on and selenium webdriver for Firefox and Chrome.

Changing User Agent for Firefox

1) First you should add User-Aget Switcher to your Firefox browser.

2) Save all device list to desktop and import it as shown below.

3) Go to Tools-> Default User Agent -> Edit User Agents

Then select Mobile Devices -> Devices -> HTC -> One M9 – Android 6.0 -Chrome 52.0 and then click Edit.

Then, you can see the user agent value of HTC One M9 as shown below. Copy and save these value for user agent manipulation in our selenium webdriver test automation code.

Test Scenario:

  • Go to www.amazon.com
  • Write “Sony Headphones” to the search bar.
  • Click search button
  • Wait until first search result’s image is visible
  • Write first search element’s text to the console

Test Code:

Changing User Agent for Chrome

1) First you should add User-Aget Switcher to your Chrome browser.

2) Go to User-Agent Switcher settings at Chrome extensions section and get desired agent’s information.

user agent

The test scenario is the same and the code is for Chrome browser is shown below.

Github: https://github.com/swtestacademy/GridTests/tree/master/src/test/java/grid/MobileUserAgent

The end!