2

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)
oberlies
  • 11,503
  • 4
  • 63
  • 110
raju
  • 4,788
  • 15
  • 64
  • 119

1 Answers1

3

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

Kien Truong
  • 11,179
  • 2
  • 30
  • 36
  • Do you know what is the corresponding import or code in python? Also import in java if I use java – raju Jun 05 '14 at 07:59
  • I just added what I think the python code looks like. I will update later if I can actually test it. Anyone are welcome to correct it if it's wrong. – Kien Truong Jun 05 '14 at 08:06
  • http://stackoverflow.com/questions/15787777/how-to-import-and-export-firefox-profile-for-selenium-webdriver-in-python – raju Jun 05 '14 at 08:15
  • I get an error when I try to change the value :( Is there any way I can overwrite them or change permissions – raju Jun 05 '14 at 08:21
  • If they don't allow you to change it, I'm afraid there's nothing you can do. – Kien Truong Jun 05 '14 at 08:25
  • Is there any way I can load my preexisting profile into my test. Because I am able to change those values manually. – raju Jun 05 '14 at 08:33
  • These frozen preferences are overwritten by Firefox Driver when it loads, you cannot change them even if you use an existing profile. – Kien Truong Jun 05 '14 at 08:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55115/discussion-between-raju-and-dikei). – raju Jun 05 '14 at 08:54
  • Is the selenium webdriver open source. Where is it hosted if it is. I can probably compile it myself and run. – raju Jun 05 '14 at 08:58