Tuesday, 16 September 2014

Language preferences in selenium


 package Testng
 import java.awt.AWTException;
import java.awt.Robot;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.Test;
public class Languagechange {
         

          public static void main(String[] args) throws IOException, AWTException{

                   // This will create firefox profile
                   FirefoxProfile fp=new FirefoxProfile();

                   // this will change the language preference and fr is the locale for france
                   fp.setPreference("intl.accept_languages", "fr");

                   // now pass this fp object to FirefoxDriver
                   WebDriver driver=new FirefoxDriver(fp);

                 //will manage to maximize a window
                   driver.manage().window().maximize();

                   //getting the url
                   driver.get("https://www.gmail.com");
                  
                   driver.findElement(By.id("Email")).clear();

                   driver.findElement(By.id("Email")).sendKeys("username");

                   driver.findElement(By.id("Passwd")).clear();

                   driver.findElement(By.id("Passwd")).sendKeys("password");

                   Robot robot = new Robot();      

                   robot.keyPress(java.awt.event.KeyEvent.VK_ENTER);

                   driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                  
                   driver.close();



          }

}

To know FAQ's in Interviews on Selenium  ClickHere
To know more on SQL Queries Required For Testers  ClickHere

1 comment:

  1. Can you tell me how to achieve the same in IE. I wasn't able to do same it in IE. Your answer will bevery helpful

    ReplyDelete