Setting preferences

Now we will learn how to set our own preferences. As an example, we will see how to change the user agent of your browser. These days, many web applications have a main site as well as a mobile site/m. site. The application will validate the user agent of the incoming request and decide whether to act as a server for a normal site or mobile site. So, in order to test your mobile site from your laptop or desktop browser, you just have to change your user agent. Let's see a code example where we can change the user-agent preference of our Firefox browser using FirefoxDriver, and send a request to the Facebook homepage. But before that, let's see the setPreference() method provided by the FirefoxProfile class:

public void ...

Get Selenium WebDriver 3 Practical Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.