Selenium webdriver 弹出窗口阻止登录Facebook

Selenium webdriver 弹出窗口阻止登录Facebook,selenium-webdriver,Selenium Webdriver,我正在尝试使用Selenium Java登录Facebook,但默认窗口正在打开,设置为“全部接受”,请帮助处理此问题。我在不同浏览器中尝试过,但问题相同。谢谢,必须单击此按钮 přijmout vše id和class值似乎是动态的,需要一个智能定位器。 data testid在每个新会话中似乎都相同,因此我将使用以下xpath: “//按钮[@data cookiebanner='accept_button']” 有关xpath的更多信息: 课程的其他部分基本上是标准的: package s

我正在尝试使用Selenium Java登录Facebook,但默认窗口正在打开,设置为“全部接受”,请帮助处理此问题。我在不同浏览器中尝试过,但问题相同。谢谢,必须单击此按钮

přijmout vše

id
class
值似乎是动态的,需要一个智能定位器。
data testid
在每个新会话中似乎都相同,因此我将使用以下xpath:
“//按钮[@data cookiebanner='accept_button']”

有关xpath的更多信息:

课程的其他部分基本上是标准的:

package selenium;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class FB {

    public static void main(String[] args) {
        openFbAndAcceptCookies();
    }
    
    public static String workingFdir = System.getProperty("user.dir");
    public static String chromedriverPath = workingFdir + "\\resources\\chromedriver.exe";  

    public static WebDriver startChromeDriver() {
        System.setProperty("webdriver.chrome.driver", chromedriverPath);
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--ignore-certificate-errors");
        options.addArguments("--start-maximized");
        WebDriver driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return driver;
    }
    
    public static void openFbAndAcceptCookies() {
        WebDriver driver = startChromeDriver();
        driver.get("https://www.facebook.com");
        driver.findElement(By.xpath("//button[@data-cookiebanner='accept_button']")).click();
    }
}

模拟单击“全部接受”或使用现有浏览器配置文件加载webdriver(使用已接受的来自fb的Cookie)。谢谢!,我是一个新的学习者,我不知道如何模拟接受一切。我尝试过窗口处理、警报、chrome选项、I-frame,但没有任何效果……请指导我。我已经检查了登录页面,使用selenium接受cookies很容易。第一次尝试就成功了。添加您的代码,包括异常跟踪(如果有)。太棒了@伯格,非常感谢,现在成功了。