我正在 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)
最佳答案
您可以使用这样的配置文件来设置首选项。
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);
关于python - 如何在 WebDriver 测试中更改 Firefox 设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24054404/