Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何处理浏览器弹出窗口(使用SeleniumWebDriver)?_Java_Selenium Webdriver - Fatal编程技术网

Java 如何处理浏览器弹出窗口(使用SeleniumWebDriver)?

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

我一直在尝试登录faceboook并使用Selenium搜索朋友。但我被困在这个特殊的弹出窗口中,无法解决这个问题以继续

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的答案。可能是重复的