首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用selenium webdriver处理chrome通知弹出窗口?

如何使用selenium webdriver处理chrome通知弹出窗口?
EN

Stack Overflow用户
提问于 2017-05-25 23:48:51
回答 7查看 9K关注 0票数 0

如果任何人使用chrome浏览器登录任何应用程序,则会出现通知弹出窗口,以保存密码/允许通知。如何通过selenium web-driver处理此通知弹出窗口?有时会出现两个弹出窗口(一个是保存密码,另一个是允许通知),.I已经尝试使用警报类处理,但无法在这方面succeeded.kindly帮助我。

EN

回答 7

Stack Overflow用户

发布于 2017-05-26 03:33:29

您可以打开使用ChromeOptions类。以下是示例代码。

代码语言:javascript
运行
复制
ChromeOptions chrome_Profile = new ChromeOptions();
chrome_Profile.addArguments("chrome.switches","--disable-extensions"); 
chrome_Profile.addArguments("--disable-save-password");
chrome_Profile.addArguments("disable-infobars");

System.setProperty("webdriver.chrome.driver","c/chromedriver.exe");
//Passing chrome_Profile while initializing the ChromeDriver    
WebDriver driver = new ChromeDriver(chrome_Profile);

如果这有帮助,请告诉我。

票数 0
EN

Stack Overflow用户

发布于 2018-01-22 17:47:07

你可以使用下面的代码来允许chrome发送通知:

代码语言:javascript
运行
复制
ChromeOptions options=new ChromeOptions();
Map<String, Object> prefs=new HashMap<String,Object>();
prefs.put("profile.default_content_setting_values.notifications", 1);
//1-Allow, 2-Block, 0-default
options.setExperimentalOption("prefs",prefs);
ChromeDriver driver=new ChromeDriver(options);
票数 0
EN

Stack Overflow用户

发布于 2018-05-30 20:08:48

代码语言:javascript
运行
复制
@Pritesh patel
 it didnt work for me.. I want to allow the flash to run
package com.selenium.Basics;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;      
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import Flash.FlashObjectWebDriver;
public class GuruPgm14FlashTesting {

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        String driverPath="C:\\selenium\\chromedriver.exe";
        System.setProperty("webdriver.chrome.driver", driverPath);

        ChromeOptions options=new ChromeOptions();
        Map<String, Object> prefs=new HashMap<String,Object>();
        prefs.put("profile.default_content_setting_values.notifications", 1);
        //1-Allow, 2-Block, 0-default
        options.setExperimentalOption("prefs",prefs);
        WebDriver driver=new ChromeDriver(options);

        driver.get("http://demo.guru99.com/test/flash-testing.html");
        Thread.sleep(5000);
        driver.findElement(By.xpath("//embed[@play='false']")).click();
        System.out.println("Clicked to allow the addon");
        Thread.sleep(5000);


        FlashObjectWebDriver fdriver= new FlashObjectWebDriver(driver, "myFlashVideo");
        fdriver.callFlashObject("Play");
        Thread.sleep(5000);
        fdriver.callFlashObject("StopPlay");
        Thread.sleep(5000);
        fdriver.callFlashObject("SetVariable","/:message","Flash testing using selenium Webdriver");
        System.out.println(fdriver.callFlashObject("GetVariable","/:message"));             

    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44184668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档