- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Set Chrome's language using Selenium ChromeDriver
We can set Chrome browser language using Selenium webdriver. Some applications are designed such that it can be redesigned to multiple languages without any modifications. This is known as internationalization.
In Selenium, we can modify the language preferences with the help of ChromeOptions class for the Chrome browser. We shall create an object of this class and apply addArguments method on it.
To modify the language to Spanish, we have to pass −−lang=es as a parameter to the addArguments method. This information is then made available to the webdriver object.
Syntax
ChromeOptions opt = new ChromeOptions(); opt.addArguments("−−lang=es"); WebDriver drv = new ChromeDriver(opt);
Example
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class ChromeLangSet{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); //ChromeOptions object ChromeOptions opt = new ChromeOptions(); //set language to Spanish opt.addArguments("−−lang=es"); // configure options parameter to Chrome driver WebDriver driver = new ChromeDriver(opt); driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS); driver.get("https://www.google.com/ "); } }
Output
Advertisements