【问题标题】:How to change Firefox settings in WebDriver test?如何在 WebDriver 测试中更改 Firefox 设置?
【发布时间】:2014-07-26 02:31:08
【问题描述】:

我在 Firefox 上用 Python 运行 WebDriver 测试。我已经配置了我的 Firefox,以确保社交网站的所有链接都在当前选项卡中打开。我特意做了以下两处改动

browser.link.open_newwindow.restriction then,  change the value to 0 (zero)
browser.link.open_newwindow and change the value to 1 (one)

可以在https://support.mozilla.org/en-US/questions/970999找到。

我的 WebDriver Firefox 设置包括

from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains

success = True
wd = WebDriver()
wd.implicitly_wait(60)

如何在开始测试代码之前将设置添加到上述设置中?

编辑

当我尝试更改 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)

【问题讨论】:

    标签: python selenium selenium-webdriver webdriver selenium-firefoxdriver


    【解决方案1】:

    您可以使用这样的配置文件设置偏好。

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.link.open_newwindow.restriction", 0);
    profile.setPreference("browser.link.open_newwindow", 1);
    WebDriver webDriver =  new FirefoxDriver(profile);
    

    python 代码可能看起来像这样,虽然我现在无法测试。

    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);
    

    来源:FirefoxDriver Tips & Tricks

    【讨论】:

    • 你知道python中对应的import或者code是什么吗?如果我使用 java,也要导入 java
    • 我刚刚添加了我认为 python 代码的样子。如果我可以实际测试它,我将在稍后更新。如有错误欢迎大家指正。
    • 尝试更改值时出现错误:( 有什么方法可以覆盖它们或更改权限
    • 如果他们不让你改,恐怕你也无能为力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 2017-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多