Java 如何处理浏览器弹出窗口(使用SeleniumWebDriver)?
我一直在尝试登录faceboook并使用Selenium搜索朋友。但我被困在这个特殊的弹出窗口中,无法解决这个问题以继续Java 如何处理浏览器弹出窗口(使用SeleniumWebDriver)?,java,selenium-webdriver,Java,Selenium Webdriver,我一直在尝试登录faceboook并使用Selenium搜索朋友。但我被困在这个特殊的弹出窗口中,无法解决这个问题以继续 public class FbAutomation { public static void main(String[] args) { FirefoxDriver browser = new FirefoxDriver(); browser.get("https://www.facebook.com/"); brows
public class FbAutomation {
public static void main(String[] args) {
FirefoxDriver browser = new FirefoxDriver();
browser.get("https://www.facebook.com/");
browser.manage().window().maximize();
browser.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
browser.findElement(By.xpath("//input[@name='email']")).sendKeys("user-email");
browser.findElement(By.xpath("//input[@name='pass']")).sendKeys("password");
/*Dimension radi = browser.findElement(By.xpath("//label[@id='loginbutton']")).getSize();
System.out.println("height is " + radi.height + " and width is " + radi.width);*/
browser.findElement(By.xpath("//label[@id='loginbutton']")).submit();
browser.navigate().to("https://www.facebook.com/imshaiknasir");
Alert alt = browser.switchTo().alert();
alt.accept();
/*
* Not able to handle "Allow notification" popUp box.
*/`enter code here`
browser.close();
}
}
此警报不是JS警报,它是特定于浏览器的,因此Selenium无法直接处理。您应该能够在每个浏览器中禁用它。有关FF,请参阅。在这个问题上,还有其他一些关于Chrome的答案。可能是重复的