There is 2 ways to test your website on mobile browser-

1) if your domain name in mobile open like-> 
then you can directly open the mobile site on simple browser opened by WebDriver and start working. 
for ex-,

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MobileSite {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();

2)  if your domain name in mobile open like–> then it is required to change the user agent while opening the browser thru selenium. By changing the user agent, it will open the browser in mobile mode (same as opened in mobile). 

Please find the code below-

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class MobileBrowser {
    public static void main(String[] args) throws InterruptedException, IOException {
        System.out.println(“program start”);
        FirefoxProfile ffprofile = new FirefoxProfile();
        ffprofile.setPreference(“general.useragent.override”, “iPhone”); //this will change the user agent which will open mobile browser 
        WebDriver driver = new FirefoxDriver(ffprofile); 
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().setSize(new Dimension(400,800)); //just to change the window size so that it will look like mobile 😉
        //lets try sign in
        driver.findElement(“nav-menu”)).click(); //click on right corner bar icon
        driver.findElement(By.xpath(“//a[@href=’/customer/login’]/img”)).click(); //click on login

Note- To write the xpath, you can use simply use as usual Firepath with Firebug only. After changing the user-agent manually in Firefox, when you will open the website, it will open as in mobile browser and now you can use firebug/firepath as usual.