If your domain name in mobile open like--> www.domainName.com 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).
-->Here in the below code, you just change "iPhone" with Android, Blackberry...to change OS type
------------------------------------------------------------------------------------
If you like the code............Just share the blog
-->Here in the below code, you just change "iPhone" with Android, Blackberry...to change OS type
------------------------------------------------------------------------------------
package mobile;
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;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class Mobilesiteopen {
@Test(description="Open facebook mobile version site using selenium webdriver")
public void fb() {
WebDriver driver = new FirefoxDriver();
WebDriverWait w = new WebDriverWait(driver,5000);
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.get("http://www.fb.com/");
driver.findElement(By.name("email")).sendKeys("username");
driver.findElement(By.name("pass")).sendKeys("************");
driver.findElement(By.name("login")).click();
w.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Logout (Sai Prasad)']")));
driver.findElement(By.xpath("//a[text()='Logout (Sai Prasad)']")).click();
}
}
----------------------------------------------------------------------------------------If you like the code............Just share the blog