如何使Firefox打开通过WebDriver在同一窗口中打开的所有链接? [英] How to make Firefox open all links opened via WebDriver in the same window?
问题描述
我试过
$ p $
profile.setPreference(browser.link.open_newwindow,1)
code> 但结果是:
警告:traffic.loop 0错误:首选项browser.link.open_external不能被覆盖:冻结值= 2,请求值= 1
是否有另一种方法可以在同一窗口中打开链接? 试试这个out ...
修改FireFox个人资料参数browser.link.open_newwindow.restriction和browser.link.open_newwindow。
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(browser.link.open_newwindow.restriction,0);
profile.setPreference(browser.link.open_newwindow,1);
如果您使用Google Chrome,只需安装这个扩展名,它将负责剩下的任务。这个扩展也很方便打开通常在新窗口中打开的新选项卡中的弹出窗口。 (首先,您需要从给定的位置下载扩展名.crx文件。)
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(/ path / to / extension.crx));
DesiredCapabilities功能=新的DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY,options);
ChromeDriver驱动程序=新的ChromeDriver(功能);
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 ?
解决方案 Try this out...
Modify FireFox profile parameters "browser.link.open_newwindow.restriction" and "browser.link.open_newwindow".
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.link.open_newwindow.restriction", 0);
profile.setPreference("browser.link.open_newwindow", 1);
If you are using Google Chrome then simply install this extension and it will take care of the rest of the task. This extension is also handy to open pop-ups in new tabs which usually opens in new windows. (First you need to download the extension .crx file from given location.)
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
这篇关于如何使Firefox打开通过WebDriver在同一窗口中打开的所有链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!