Selenium无法通过Google Chrome接受警报[java]

时间:2015-07-22 14:50:14

标签: java google-chrome selenium selenium-webdriver

Selenium无法通过Google Chrome接受提醒。

    driver.get("http://bubble-export.com/lpg2/");
    driver.get("http://google.com");
    Alert alert = driver.switchTo().alert();
    alert.accept();

Firefox和IE运行良好。购买谷歌浏览器无法正常工作!!

如何通过Google Chrome接受警报!?

  (Session info: chrome=44.0.2403.89)

  (Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.9.5 x86_64) 
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-27 00:00:10'

   os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.8.0_40'

Driver info: org.openqa.selenium.chrome.ChromeDriver

1 个答案:

答案 0 :(得分:2)

而不是接受警报。你可以将其作为黑客攻击。它会删除出现的警告

    WebDriver driver = new ChromeDriver();
    driver.get("http://bubble-export.com/lpg2/");
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("window.onbeforeunload = function() {};");
    driver.get("http://google.com");