Reputation: 5008
I am running WebDriver tests in Python on Firefox. I have configured my Firefox to make sure all the links of social networking sites are opened in the current tab. I specifically made following two changes
browser.link.open_newwindow.restriction then, change the value to 0 (zero)
browser.link.open_newwindow and change the value to 1 (one)
It can be found in https://support.mozilla.org/en-US/questions/970999.
My WebDriver Firefox setup consists of
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
success = True
wd = WebDriver()
wd.implicitly_wait(60)
How do I also add the settings to the above setup before starting the test code?
Edit
I get the following error when I try to change value of browser.link.open_newwindow
Exception in thread "main" java.lang.IllegalArgumentException: Preference browser.link.open_newwindow may not be overridden: frozen value=2, requested value=1
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:120)
at org.openqa.selenium.firefox.Preferences.checkPreference(Preferences.java:223)
at org.openqa.selenium.firefox.Preferences.setPreference(Preferences.java:161)
at org.openqa.selenium.firefox.FirefoxProfile.setPreference(FirefoxProfile.java:230)
at tmp.main(tmp.java:21)
Upvotes: 2
Views: 3552
Reputation: 11381
You can set the preference using a profile like this.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.link.open_newwindow.restriction", 0);
profile.setPreference("browser.link.open_newwindow", 1);
WebDriver webDriver = new FirefoxDriver(profile);
The python code will probably look like this, though I can't test right now.
from selenium import webdriver
profile = webdriver.FirefoxProfile();
profile.set_preference("browser.link.open_newwindow.restriction", 0);
profile.set_preference("browser.link.open_newwindow", 1);
wd = webdriver.Firefox(profile);
Source: FirefoxDriver Tips & Tricks
Upvotes: 3