Reputation: 952
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
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