Kemat Rochi
Kemat Rochi

Reputation: 952

How to open a mobile version website using Selenium WebDriver?

I have the following code to open the mobile version of Facebook in Firefox in my Desktop by changing the user-agent.

@Test
public void fb() {
        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 ;)
        driver.navigate().to("http://www.facebook.com/");
        driver.findElement(By.name("email")).sendKeys("username");
        driver.findElement(By.name("pass")).sendKeys("************");
        driver.findElement(By.name("login")).click();
    }

But for some reason, it doesn't seem to work quite right. Can anyone let me know what I'm doing wrong here?

Upvotes: 1

Views: 2857

Answers (1)

Hudson
Hudson

Reputation: 407

try sending a request to http://m.facebook.com, this is facebooks mobile website, This will only work if its just for facebook though.

Upvotes: 4

Related Questions