How to close Chrome browser popup?

I write code for Facebook, where it takes the URL, ID, password from the properties file, but when I logged in, I hinted that "Facebook wants to show notifications - allow-block." How to do this after logging in (A.) Presses ESP or ALT + F4 and closes the pop-up window or (B.) Finds a notification and closes it itself. This is what I use but does not work. Any help is appreciated.

    public void closePopup() throws InterruptedException{

    Thread.sleep(1000);
    Actions action=new Actions(driver);

    action.keyDown(Keys.ESCAPE).keyUp(Keys.ESCAPE).build().perform();
+4
source share
2 answers

After further research, I found my answer. This is a Chrome notification, so here is the necessary step to solve my problem.

        ChromeOptions ops = new ChromeOptions();
        ops.addArguments("--disable-notifications");
        System.setProperty("webdriver.chrome.driver", "./lib/chromedriver");
        driver = new ChromeDriver(ops);
+1

:

1:

// ChromeOptions

ChromeOptions options = new ChromeOptions();

2:

// - " - -"

options.addArguments("--disable-notifications");

3:

// exe

System.setProperty("webdriver.chrome.driver","path/to/driver/exe");

4:

// ChromeOptions ChromeDriver

WebDriver driver =new ChromeDriver(options);
0

Source: https://habr.com/ru/post/1665430/


All Articles