简体   繁体   English

如何使用 Selenium/java 在 Google Chrome 的弹出通知中选择“始终允许”?

[英]How do I choose to "always allow" in the popup notification in Google Chrome with Selenium/java?

Popup notification弹出通知

I am creating a program to automate whatsapp messages to some clients, but a notification appears on the screen, I would like to press always allow to advance in the process.我正在创建一个程序来自动向某些客户端发送 whatsapp 消息,但屏幕上会出现一条通知,我想按始终允许在此过程中前进。 Using Selenium with java.使用 Selenium 和 java。

I already tried using code to deactivate the pop-up notifications but it doesn't work, so I would like to accept the permission so that the notification does not appear, I want to change the permissions so that the popup notification does not appear.我已经尝试使用代码来停用弹出通知,但它不起作用,所以我想接受权限以便通知不会出现,我想更改权限以便弹出通知不会出现。

import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;

/**
*
* @author DiseñoVerde
*/
public class Abrir_con_Chrome {
   
 
 public int enviarnumero(int numero) {

       int num = numero;
       
       System.setProperty("webdriver.chrome.driver", "C:\\Users\\DiseñoVerde\\OneDrive\\WhatsappDirect\\driver\\chromedriver.exe");

       ChromeOptions options = new ChromeOptions();
       
       Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
prefs.put("profile.managed_default_content_settings.notifications", 1);

options.setExperimentalOption("prefs", prefs);
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--disable-notifications");



       
       WebDriver wd = new ChromeDriver(options);
      

       Actions builder = new Actions(wd);
       
       wd.get("https://wa.me/505" + num);
      

       return 0;

   }
}

I wait your answer thank you!我等你的答复谢谢!

// Try using chrome options as below.  
  Map<String, Object> pref = 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);

// if it does not work , you need to check outside selenium.

I had a similar issue some time ago.我前段时间遇到过类似的问题。 As far as I remember it's not really possible to interact with those popups using selenium since it's not a part of website but rather something rendered by the browser itself.据我所知,实际上不可能使用 selenium 与这些弹出窗口进行交互,因为它不是网站的一部分,而是由浏览器本身呈现的内容。

You can try disabling the popups via ChromeOptions like this您可以像这样尝试通过 ChromeOptions 禁用弹出窗口

options.addArguments("--disable-popup-blocking");

depending on your chromedriver version this might not work.根据您的 chromedriver 版本,这可能不起作用。 If so, try the following:如果是这样,请尝试以下操作:

ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("excludeSwitches",Arrays.asList("disable-popup-blocking")); caps.setCapability(ChromeOptions.CAPABILITY, options);

references:参考:

https://www.browserstack.com/docs/automate/selenium/enable-pop-ups https://www.browserstack.com/docs/automate/selenium/enable-pop-ups

https://newbedev.com/how-to-click-allow-on-show-notifications-popup-using-selenium-webdriver https://newbedev.com/how-to-click-allow-on-show-notifications-popup-using-selenium-webdriver

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Firefox 中使用 Selenium WebDriver 和 Java 允许或拒绝麦克风和摄像头弹出通知 - How to allow or deny notification of microphone and camera popup in Firefox using Selenium WebDriver with Java 如何通过使用Java在Selenium Webdriver中的弹出窗口上单击允许按钮 - How to click on allow button on popup window in selenium Webdriver by using Java 如何使用Java处理Selenium中的浏览器通知弹出窗口? - How to handle the browser notification popup in selenium using java? 如何让用户轻松选择在Java Swing应用程序中分配多少内存? - How do I allow the user to easily choose how much memory to allocate in a Java Swing app? 在Chrome浏览器中。 如果您的连接不安全,则身份验证弹出代码不适用于使用Java的Selenium。 - in Chrome browser. authentication popup code not working with Selenium using Java if your connection is not secure notification appears 如何使用 Java 使用 Selenium WebDriver 在 Chrome 中处理身份验证弹出窗口 - How to handle authentication popup in Chrome with Selenium WebDriver using Java 如何在 heroku google chrome 上部署 selenium java - How to deploy selenium java on heroku google chrome Java-硒允许弹出窗口 - Java-Selenium Allow Popup Window 如何使用 Selenium Java 在 Chrome 浏览器中摆脱 cookie 通知 - How to get rid of cookies notification in chrome browser using Selenium Java 如何在Selenium java中选择select - How to choose select in Selenium java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM