2016-05-17 83 views

回答

0

使用的代碼片段:

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

不適用於我。它會引發錯誤:「發生異常:org.openqa.selenium.NoAlertPresentException」。它不是JavaScript警報。彈出窗口來自瀏覽器地址欄,請求用戶在設備上存儲文件的權限。 – mahesh

0

你好,請使用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

希望這可以幫助你