![](/img/trans.png)
[英]How to allow or deny notification of microphone and camera popup in Firefox using Selenium WebDriver with Java
[英]How do I choose to "always allow" in the popup notification in Google Chrome with Selenium/java?
我正在创建一个程序来自动向某些客户端发送 whatsapp 消息,但屏幕上会出现一条通知,我想按始终允许在此过程中前进。 使用 Selenium 和 java。
我已经尝试使用代码来停用弹出通知,但它不起作用,所以我想接受权限以便通知不会出现,我想更改权限以便弹出通知不会出现。
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;
}
}
我等你的答复谢谢!
// 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.
我前段时间遇到过类似的问题。 据我所知,实际上不可能使用 selenium 与这些弹出窗口进行交互,因为它不是网站的一部分,而是由浏览器本身呈现的内容。
您可以像这样尝试通过 ChromeOptions 禁用弹出窗口
options.addArguments("--disable-popup-blocking");
根据您的 chromedriver 版本,这可能不起作用。 如果是这样,请尝试以下操作:
ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("excludeSwitches",Arrays.asList("disable-popup-blocking")); caps.setCapability(ChromeOptions.CAPABILITY, options);
参考:
https://www.browserstack.com/docs/automate/selenium/enable-pop-ups
https://newbedev.com/how-to-click-allow-on-show-notifications-popup-using-selenium-webdriver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.