2015-04-06 52 views
0

請幫我在Safari處理警報如何處理硒中SafariDriver的警報?

結果,我在這下面得到的是Safari瀏覽器無法處理警報那麼,有沒有其他的方法來處理

package Default; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.Alert; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.safari.SafariDriver; 

public class Safari_demo { 

    public static void main(String[] args) throws InterruptedException{ 

     WebDriver driver = new SafariDriver(); 

     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 

     driver.get("http://www.htmlite.com/JS002.php"); 

     Thread.sleep(6000); 

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

     driver.close(); 
    } 

} 
+0

任何解決方案?它似乎不支持,這完全限制了很多硒測試的Safari – uchuugaka 2015-04-21 05:04:11

回答

1

您需要explicitly wait for the alert to appear警報:

WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.alertIsPresent()); 

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

嗨,謝謝,但我很遺憾地告訴它沒有工作 – 2015-04-07 04:35:51

+0

@ShiyadShafee有什麼症狀? – alecxe 2015-04-07 17:26:13

相關問題