2

Firefox で Python で WebDriver テストを実行しています。ソーシャル ネットワーキング サイトのすべてのリンクが現在のタブで開かれるように Firefox を構成しました。具体的には次の2つの変更を加えました

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

1 に答える 1

3

このようなプロファイルを使用してプリファレンスを設定できます。

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 のヒントとコツ

于 2014-06-05T07:56:33.230 に答える