How to change language in web page using Selenium(Java)? - java

Is their a way to pre-define a language for webpage? I want to load google page in Spanish, can we set property of webdriver in such a way that it load the page in Spanish.

Check this link:
For Firefox:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference( "intl.accept_languages", "es" );
WebDriver driver = new FirefoxDriver(profile);
For Chrome:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--lang=es");
ChromeDriver driver = new ChromeDriver(options);

Related

Selenium Launches Firefox While Silently Ignoring Profile Preference

There are currently two recommended ways to launch the latest version of Selenium using a specific profile. One is through the Desired Capabilities object and the other us by using Firefox Options.
Desired Capabilities:
public static WebDriver launchFirefoxProfileByFFCapabilities()
{
WebDriver driver = null;
System.setProperty("webdriver.gecko.driver", "PATH");
ProfilesIni profile = new ProfilesIni();
String profileName = "Profile_1";
FirefoxProfile firefoxProfileByProfilesIni = profile.getProfile(profileName);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, firefoxProfileByProfilesIni);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
driver = new FirefoxDriver(opt);
return driver;
}
Firefox Options:
public static WebDriver launchFirefoxProfileByFFOptions()
{
WebDriver driver = null;
System.setProperty("webdriver.gecko.driver", "PATH");
ProfilesIni profile = new ProfilesIni();
String profileName = "Profile_1";
FirefoxProfile firefoxProfileByProfilesIni = profile.getProfile(profileName);
FirefoxOptions opt = new FirefoxOptions();
opt.setProfile(firefoxProfileByProfilesIni);
driver = new FirefoxDriver(opt);
return driver;
}
I noticed a few interesting discrepancies between the two approaches and I'm trying to understand what is the reason for these discrepancies and how to prevent them.
1) With Firefox Options when the specified Profile Name does not exist (as it appears in the Firefox - Choose User Profile dialog) throws WebDriverException: Unexpected value for profile: null. However with Desired Capabilities no such exception is thrown and Selenium silently ignores the profile preference (which is not ideal)
2) If the Profile Name exists (as it appears in the Firefox - Choose User Profile dialog) but the path in profiles.ini file is incorrect even Firefox Options will launch silently ignore the profile preference and launch WebDriver not connected to any profile
What is the cause of these discrepancies? How can they be prevented?
Thanks
It seems that Capabilities and FirefoxProfile/FirefoxOptions handle the profileIni in a different way.
Could you please modify and add the stack-traces so we can further help you?

How do I handle allow pop-up of plug-in for firefox using Selenium Webdriver with Java

While automating the web page which includes Vidyo Web player plugin.
If I am navigating to the Video page, the allow pop-up is showing.
I have tried to with the below code to handle allow pop-up. But it's not working.
Below is the code which am using,
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("security.mixed_content.block_active_content", true);
profile.setPreference("security.mixed_content.block_display_content", false);
WebDriver driver = new FirefoxDriver(profile);
Can any one help on this?
Thanks in Advance.
Referencing this answer, you probably need to source the file for the extension and use the below:
File file = new File("path to extension file");
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(file);
WebDriver driver = new FirefoxDriver(profile);
How about this preference:
FirefoxProfile profile= new FirefoxProfile();
profile.setPreference(“browser.popups.showPopupBlocker”, false);
WebDriver driver = new FirefoxDriver(profile);
Try to set this preference to get rid of "Allow"/"Continue Blocking":
profile.setPreference("plugin.scan.plid.all", false);
Also you might need to use this to automatically allow extension
profile.setPreference("extensions.blocklist.enabled", false);

How to Disable JavaScript in WebDriver when automating in Selenium?

I am currently trying to write a test that tests the non-JS version of my website. I use Selenium with Java. I have tried this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", false);
driver = new FirefoxDriver(profile);
driver.get();
However this isn't working. It just loads the page with JavaScript Enabled.
As a workaround I did, this, for the requirement.
It will manually set the javascript.enabled property to false by the following script.
WebDriver driver = new FirefoxDriver();
driver.get("about:config");
Actions act = new Actions(driver);
act.sendKeys(Keys.RETURN).sendKeys("javascript.enabled").perform();
act.sendKeys(Keys.TAB).sendKeys(Keys.RETURN).perform();

How to set set capability for chrome in selenium?

How to use this method? What parameter should I pass to "capabilityName" and "value"?
public void setCapability(java.lang.String capabilityName,java.lang.String value);
For Chrome specifically, you can find the capabilities here: https://sites.google.com/a/chromium.org/chromedriver/capabilities-aka-chromeoptions
There is a more general overview of capabilities on the selenium wiki: http://code.google.com/p/selenium/wiki/DesiredCapabilities
Here is an example that maximizes the browser window (for chrome). Enable/Disable the second while running it and see the difference.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");

How to disable geolocation permissions for a website using firefox capabilities in selenium webdriver

I want to disable the geolocation permissions for a website using firefox capabilities in selenium webdriver, but i am not able to do so.
I tried doing this...
WebDriver d = null;
cap = cap.merge(DesiredCapabilities.firefox());
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("geo.enabled", false);
cap.setCapability("geo.provider.use_corelocation", false);
cap.setCapability("geo.prompt.testing", false);
cap.setCapability("geo.prompt.testing.allow", false);
Attached is the screenshot of the same
I haven't tried with your specific parameter but for others it works well, like this:
FirefoxProfile profile = new FirefoxProfile();
// Turn off updates
profile.setPreference("app.update.enabled", false);
WebDriver driver = new FirefoxDriver(profile);
Using Selenium 2.48 and FF 42.0 (but it should do for other versions, as well.
This worked for me
caps.setCapability("locationContextEnabled", false);

Categories