selenium不能接受谷歌浏览器发出的警报。
driver.get("http://bubble-export.com/lpg2/"); driver.get("http://google.com"); Alert alert = driver.switchTo().alert(); alert.accept();
Firefox和IE运作良好。购买Google chrome无效!
我如何接受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
而不是接受警报。您可以将其作为骇客操作。这将删除警报,使其不再显示
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");