Run mobile based web browser automation testing on PC Web browser using Java – Selenium

In-order to run the mobile browser automation on PC’s browser we need to change the browser user agent.

Note : In the below example/snippet I’m considering chrome as my default browser.

Below I’ve listed the steps.

  1. First choose the right browser , in this case for example I’ve taken Google chrome.
  2. Open the Chrome Desired capabilities and add the below code.

options.addArguments(“–user-agent=Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36”);


Now run the respective test script and you should observe that the web browser acts as a mobile browser.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s