硒Python Firefox webdriver:无法修改配置文件 [英] Selenium Python Firefox webdriver : can't modify profile

查看:236
本文介绍了硒Python Firefox webdriver:无法修改配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个webdriver Firefox实例上使用新选项卡而不是窗口选项。
1 /我用这个选项创建了一个配置文件,但是当我使用这个配置文件时,很多选项都可以,但是不是这个。
2 /在配置文件加载后,我尝试更改代码中的选项,但不起作用。
我的代码:

$ p $ profile = webdriver.FirefoxProfile(os.path.join(s_path,name))
profile.set_preference(browser.link.open_newwindow.restriction,0)
profile.set_preference(browser.link.open_newwindow,3)
profile.set_preference(browser.link.open_external ,3)
profile.set_preference(browser.startup.homepage,http://www.google.fr)
profile.update_preferences()
print(os.path .join(s_path,name))
driver = webdriver.Firefox(set_profile())

一切正常(开始的主页是google.fr)除了这个选项不正确。



看来Selenium复制配置文件在一个临时目录。 users.js有错误的行:

$ p $ user_pref(browser.link.open_newwindow,2);

Python 3.4.2,Windows 7,Firefox 39.0,Selenium lib 2.46

解决方案

从我研究的内容来看, ,它总是与值 2 同步。如果你挖掘了Python绑定的来源,你会发现一个设置 frozen 设置,然后设置自定义设置。



请注意,在 $ b这个默认冻结设置的设置是明确的硬编码的:
$ b

  / ** 
*对于正确运行FirefoxDriver必不可少的配置文件首选项。用户不能
*被允许覆盖这些值。
* /
private static final ImmutableMap< String,Object> < String,Object> builder()
.put(app.update.auto,false)
.put(app.update.enabled,false )
.put(browser.download.manager.showWhenStarting,false)
.put(browser.EULA.override,true)
.put(browser.EULA.3 .accepted,true)
.put(browser.link.open_external,2)
.put(browser.link.open_newwindow,2)//这里是
/ / ...

以下是 Firefox只支持Windows而不是标签


这是一个已知的问题,不幸的是我们不会支持标签。

我们强制Firefox在新窗口中打开所有链接。我们无法访问
标签来了解何时切换。当我们转移到木偶(Mozilla
项目)将来,我们应该能够做到这一点,但现在是
按预期工作

解决方法是更改目标手动链接 - 可能无法在所有情况下工作取决于如何打开一个新的链接。


I want to use, on a webdriver Firefox instance, the "new tab instead of window" option. 1/ I created a profile with this option on, but when I use the profile a lot of options are OK but not this one. 2/ After the load of the profile I tried to change the option in the code but it does n't work. My code :

profile = webdriver.FirefoxProfile(os.path.join(s_path, name))
profile.set_preference("browser.link.open_newwindow.restriction", 0)
profile.set_preference("browser.link.open_newwindow", 3)
profile.set_preference("browser.link.open_external", 3)
profile.set_preference("browser.startup.homepage","http://www.google.fr")
profile.update_preferences()
print(os.path.join(s_path, name))
driver = webdriver.Firefox(set_profile())

All is OK (the start homepage is google.fr) except this option which is not OK.

It seems that Selenium copy the profile in a temp dir. where users.js have the wrong line :

user_pref("browser.link.open_newwindow", 2);

Python 3.4.2, Windows 7, Firefox 39.0, Selenium lib 2.46

解决方案

From what I've researched, browser.link.open_newwindow is a frozen setting and it's always synced with the value 2. If you dig up the source of the selenium Python bindings, you would find a set of frozen settings that is applied after your custom settings are set.

Note that in java bindings this set of default frozen settings is explicitly hardcoded:

  /**
   * Profile preferences that are essential to the FirefoxDriver operating correctly. Users are not
   * permitted to override these values.
   */
  private static final ImmutableMap<String, Object> FROZEN_PREFERENCES =
      ImmutableMap.<String, Object>builder()
          .put("app.update.auto", false)
          .put("app.update.enabled", false)
          .put("browser.download.manager.showWhenStarting", false)
          .put("browser.EULA.override", true)
          .put("browser.EULA.3.accepted", true)
          .put("browser.link.open_external", 2)
          .put("browser.link.open_newwindow", 2)  // here it is
          // ...

And a bit of an explanation coming from Firefox only supports windows not tabs:

This is a known issue and unfortunately we will not be supporting tabs.

We force Firefox to open all links in a new window. We can't access the tabs to know when to switch. When we move to marionette (Mozilla project) in the future we should be able to do this but for now it is working as intended

A workaround solution would be to change the target of a link manually - may not work in all of the cases depending on how a new link is opened.

这篇关于硒Python Firefox webdriver:无法修改配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆