2016-06-24 6 views
0

ログインが失敗した場合、通知(https://developer.mozilla.org/en-US/docs/Web/API/notification)または警告(通知が無効の場合)を示す簡単なユーザーログインがあります。セレンのクロームドライバでブラウザの通知を無効にする

さらに、このログインはNodeJSのセレンでテストしたいが、通知はない(アラートのみ)。そこで、私はchrome実験オプションを使用してchromeの通知機能を無効にしようとしました。それにもかかわらず、通知は表示されません。おそらく、この機能はatmでサポートされていない可能性があります。

私はNodeJSに次のように試してみた:

var options = new chrome.Options(); 
options.addArguments("profile.default_content_setting_values.notifications", "2"); 
var driver = new webdriver.Builder().withCapabilities(options.toCapabilities()).build(); 

次のコードは、Javaで動作します。

Map<String, Object> prefs = new HashMap<String, Object>(); 
prefs.put("profile.default_content_setting_values.notifications", 2); 
ChromeOptions options = new ChromeOptions(); 
options.setExperimentalOption("prefs", prefs); 
WebDriver driver = new ChromeDriver(options); 

答えて

1

私はuserPreferencesを設定する必要がありました。

var options = new chrome.Options(); 
options.setUserPreferences({'profile.default_content_setting_values.notifications': 2}); 
var driver = new webdriver.Builder().withCapabilities(options.toCapabilities()).build(); 
0

以下のコードが動作します。 これは、私は、ユーザーが場所の設定を有効にするには、JSとJavaの仕事のためのコードスニペットの下WebdriverIO nodeJS bindings.Theを使用している場合は特に多くのクライアントからこの問題を参照してくださいクローム

ChromeOptions opt = new ChromeOptions(); 
opt.AddArguments("--disable-notifications"); 
opt.AddArguments("--disable-popup-blocking"); 
driver = new ChromeDriver(@"C:\Users\ChromeDriverPath", opt); 
0

のためだけである:

についてJS:Java用

var options = new chrome.Options(); 
    options.setUserPreferences({'profile': {'managed_default_content_settings': {'geolocation': 1}}}); 
    var driver = new webdriver.Builder().forBrowser('chrome').withCapabilities(options.toCapabilities()).build(); 

// Declare variables 
ChromeOptions options = new ChromeOptions(); 
Map<String, Object> prefs = new HashMap<String, Object>(); 
Map<String, Object> profile = new HashMap<String, Object>(); 
Map<String, Object> contentSettings = new HashMap<String, Object>(); 
// Specify the ChromeOption we need to set 
contentSettings.put(“geolocation”, 1); 
profile.put(“managed_default_content_settings”, contentSettings); 
prefs.put(“profile”, profile); 
options.setExperimentalOption(“prefs”, prefs); 
// Declare the capability for ChromeOptions 
caps.setCapability(ChromeOptions.CAPABILITY, options); 

試してみて、物事がどのように進むのか教えてください。

関連する問題