<small id='ufNqV'></small><noframes id='ufNqV'>

      <bdo id='ufNqV'></bdo><ul id='ufNqV'></ul>

    <i id='ufNqV'><tr id='ufNqV'><dt id='ufNqV'><q id='ufNqV'><span id='ufNqV'><b id='ufNqV'><form id='ufNqV'><ins id='ufNqV'></ins><ul id='ufNqV'></ul><sub id='ufNqV'></sub></form><legend id='ufNqV'></legend><bdo id='ufNqV'><pre id='ufNqV'><center id='ufNqV'></center></pre></bdo></b><th id='ufNqV'></th></span></q></dt></tr></i><div id='ufNqV'><tfoot id='ufNqV'></tfoot><dl id='ufNqV'><fieldset id='ufNqV'></fieldset></dl></div>
    1. <legend id='ufNqV'><style id='ufNqV'><dir id='ufNqV'><q id='ufNqV'></q></dir></style></legend>
    2. <tfoot id='ufNqV'></tfoot>
    3. 如何使用 Selenium Webdriver 处理浏览器级别的通知

      时间:2023-07-13
          <bdo id='jLPwg'></bdo><ul id='jLPwg'></ul>
            <tbody id='jLPwg'></tbody>

          <small id='jLPwg'></small><noframes id='jLPwg'>

            1. <legend id='jLPwg'><style id='jLPwg'><dir id='jLPwg'><q id='jLPwg'></q></dir></style></legend>
            2. <tfoot id='jLPwg'></tfoot>

              1. <i id='jLPwg'><tr id='jLPwg'><dt id='jLPwg'><q id='jLPwg'><span id='jLPwg'><b id='jLPwg'><form id='jLPwg'><ins id='jLPwg'></ins><ul id='jLPwg'></ul><sub id='jLPwg'></sub></form><legend id='jLPwg'></legend><bdo id='jLPwg'><pre id='jLPwg'><center id='jLPwg'></center></pre></bdo></b><th id='jLPwg'></th></span></q></dt></tr></i><div id='jLPwg'><tfoot id='jLPwg'></tfoot><dl id='jLPwg'><fieldset id='jLPwg'></fieldset></dl></div>
                本文介绍了如何使用 Selenium Webdriver 处理浏览器级别的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 Selenium Webdriver 和核心 Java 自动化一些测试用例,在 Chrome 浏览器中单击按钮时的一个测试用例我收到浏览器级通知显示带有选项允许和阻止的通知".我想选择允许选项.谁能知道如何使用 Selenium webdriver 处理这种通知.请参阅以下快照以获取更多详细信息

                解决方案

                请按以下步骤操作:

                A) 使用 JAVA:

                <块引用>

                对于旧 Chrome 版本 (<50):

                //创建ChromeOptions类的实例ChromeOptions 选项 = 新 ChromeOptions();//添加chrome开关禁用通知-**--disable-notifications**"options.addArguments("--disable-notifications");//设置驱动exe的路径System.setProperty("webdriver.chrome.driver","path/to/driver/exe");//将 ChromeOptions 实例传递给 ChromeDriver 构造函数WebDriver 驱动 =new ChromeDriver(options);

                <小时><块引用>

                对于新的 Chrome 版本 (>50):

                //创建一个地图来存储偏好映射<字符串,对象>prefs = new HashMap<String, Object>();//添加键和值到映射如下关闭浏览器通知//传递参数1允许,2阻止prefs.put("profile.default_content_setting_values.notifications", 2);//创建一个ChromeOptions实例ChromeOptions 选项 = 新 ChromeOptions();//设置 ExperimentalOption - 首选项options.setExperimentalOption("prefs", prefs);//现在将 ChromeOptions 实例传递给 ChromeDriver 构造函数以初始化 chrome 驱动程序,这将在 chrome 浏览器上关闭此浏览器通知WebDriver driver = new ChromeDriver(options);

                <小时><块引用>

                对于火狐:

                 WebDriver 驱动程序;FirefoxProfile 配置文件 = 新的 FirefoxProfile();profile.setPreference("permissions.default.desktop-notification", 1);DesiredCapabilities 能力=DesiredCapabilities.firefox();能力.setCapability(FirefoxDriver.PROFILE,配置文件);驱动程序=新的FirefoxDriver(功能);driver.get("http://google.com");

                <小时>

                B) 使用 Python:

                从 selenium 导入 webdriver从 selenium.webdriver.chrome.options 导入选项选项 = 选项()option.add_argument("--disable-infobars")option.add_argument("开始最大化")option.add_argument("--disable-extensions")# 传递参数 1 表示允许,2 表示阻止option.add_experimental_option(首选项",{profile.default_content_setting_values.notifications":1})driver = webdriver.Chrome(chrome_options=option, executable_path='path-of-驱动程序chromedriver.exe')driver.get('https://www.facebook.com')

                C) 使用 C#:

                ChromeOptions 选项 = new ChromeOptions();options.AddArguments("--disable-notifications");//禁用通知IWebDriver driver = new ChromeDriver(options);

                I am Automating some test cases using Selenium Webdriver and core Java,in chrome browser for one test case on clicking button I am getting browser level notification 'Show notifications with options Allow and Block'. I want to select Allow option. Can anyone know how to handle this kind of notifications using Selenium webdriver. please refer following snapshot for more details

                解决方案

                Please Follow below steps :

                A) USING JAVA :

                For Old Chrome Version (<50):

                //Create a instance of ChromeOptions class
                ChromeOptions options = new ChromeOptions();
                
                //Add chrome switch to disable notification - "**--disable-notifications**"
                options.addArguments("--disable-notifications");
                
                //Set path for driver exe 
                System.setProperty("webdriver.chrome.driver","path/to/driver/exe");
                
                //Pass ChromeOptions instance to ChromeDriver Constructor
                WebDriver driver =new ChromeDriver(options);
                


                For New Chrome Version (>50):

                //Create a map to store  preferences 
                Map<String, Object> prefs = new HashMap<String, Object>();
                
                //add key and value to map as follow to switch off browser notification
                //Pass the argument 1 to allow and 2 to block
                prefs.put("profile.default_content_setting_values.notifications", 2);
                
                //Create an instance of ChromeOptions 
                ChromeOptions options = new ChromeOptions();
                
                // set ExperimentalOption - prefs 
                options.setExperimentalOption("prefs", prefs);
                
                //Now Pass ChromeOptions instance to ChromeDriver Constructor to initialize chrome driver which will switch off this browser notification on the chrome browser
                WebDriver driver = new ChromeDriver(options);
                


                For Firefox :

                    WebDriver driver ;
                    FirefoxProfile profile = new FirefoxProfile();
                    profile.setPreference("permissions.default.desktop-notification", 1);
                    DesiredCapabilities capabilities=DesiredCapabilities.firefox();
                    capabilities.setCapability(FirefoxDriver.PROFILE, profile);
                    driver = new FirefoxDriver(capabilities);
                    driver.get("http://google.com");
                


                B) USING PYTHON :

                from selenium import webdriver
                from selenium.webdriver.chrome.options import Options
                
                option = Options()
                
                option.add_argument("--disable-infobars")
                option.add_argument("start-maximized")
                option.add_argument("--disable-extensions")
                
                # Pass the argument 1 to allow and 2 to block
                option.add_experimental_option("prefs", { 
                    "profile.default_content_setting_values.notifications": 1 
                })
                
                driver = webdriver.Chrome(chrome_options=option, executable_path='path-of- 
                driverchromedriver.exe')
                driver.get('https://www.facebook.com')
                

                C) USING C#:

                ChromeOptions options = new ChromeOptions();
                options.AddArguments("--disable-notifications"); // to disable notification
                IWebDriver driver = new ChromeDriver(options);
                

                这篇关于如何使用 Selenium Webdriver 处理浏览器级别的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Selenium2 和 webdriver 的一个很好的工作示例 下一篇:如何从 RemoteWebDriver 服务器而不是本地 FirefoxDriver 获取屏幕截图?

                相关文章

                  <tfoot id='5lOUB'></tfoot>

                1. <small id='5lOUB'></small><noframes id='5lOUB'>

                  • <bdo id='5lOUB'></bdo><ul id='5lOUB'></ul>
                  <i id='5lOUB'><tr id='5lOUB'><dt id='5lOUB'><q id='5lOUB'><span id='5lOUB'><b id='5lOUB'><form id='5lOUB'><ins id='5lOUB'></ins><ul id='5lOUB'></ul><sub id='5lOUB'></sub></form><legend id='5lOUB'></legend><bdo id='5lOUB'><pre id='5lOUB'><center id='5lOUB'></center></pre></bdo></b><th id='5lOUB'></th></span></q></dt></tr></i><div id='5lOUB'><tfoot id='5lOUB'></tfoot><dl id='5lOUB'><fieldset id='5lOUB'></fieldset></dl></div>
                2. <legend id='5lOUB'><style id='5lOUB'><dir id='5lOUB'><q id='5lOUB'></q></dir></style></legend>