Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Firefox open all links opened via WebDriver in the same window?

I want to open all links in the same window instead in new window. I tried

profile.setPreference("browser.link.open_newwindow", 1)

but the result is:

WARNING: traffic.loop 0 error: Preference browser.link.open_external may not be overridden: frozen value=2, requested value=1

Is there an another way to open the links in the same window ?

like image 257
Petko Petkov Avatar asked Feb 22 '13 16:02

Petko Petkov


1 Answers

You should modify the firefox profile parameters:

profile = webdriver.FirefoxProfile()

profile.set_preference("browser.link.open_newwindow", 3)

profile.set_preference("browser.link.open_newwindow.restriction", 0)

driver = webdriver.Firefox(firefox_profile=profile)

if this methode does not work, you can set perference using firefox Options:

from selenium.webdriver.firefox.options import Options

opts = Options()

opts.set_preference("browser.link.open_newwindow.restriction", 0)

opts.set_preference("browser.link.open_newwindow", 3)

driver = webdriver.Firefox(firefox_options=opts)


(A) browser.link.open_newwindow - for links in Firefox tabs :

3 : divert new window to a new tab (default)

2 : allow link to open a new window

1 : force new window into same tab

(B) browser.link.open_newwindow.restriction - for links in Firefox tabs

0 : apply the setting under (A) to ALL new windows (even script windows)

2 : apply the setting under (A) to normal windows, but NOT to script windows with features (default)

1 : override the setting under (A) and always use new windows

like image 81
Matoussi Walid Avatar answered Oct 30 '22 17:10

Matoussi Walid