通过硒驱动程序关闭浏览器的存储权限

问题描述:

有一些浏览器原生弹出窗口。我想通过Selinium关闭这些。通过硒驱动程序关闭浏览器的存储权限

例如,当应用程序试图访问您的本地存储并且会要求您的许可时。

这样的弹出窗口阻止硒流。

Click here to view screen shot of the popup

+0

mahes可以请你张贴弹出的屏幕截图 –

使用的代码片段:

Alert alert = driver.switchTo().alert(); 
alert.accept(); 
+0

不适用于我。它会引发错误:“发生异常:org.openqa.selenium.NoAlertPresentException”。它不是JavaScript警报。弹出窗口来自浏览器地址栏,请求用户在设备上存储文件的权限。 – mahesh

你好,请使用Java Robot类,关闭该浏览器基于弹出窗口

Robot robot = new Robot(); 
// now try to press tab with robot (by doing this you can make focus of your control) 
// then simply click with the help of robot 

// for robot methods please check this link 

https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html

希望这可以帮助你