[英]How do I choose to "always allow" in the popup notification in Google Chrome with Selenium/java?
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.