Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a chrome browser pop up window?

I am writing a code for Facebook where it takes the URL, ID, Password from a properties file but upon logging in I am hinted with a "Facebook wants to show notifications - Allow - Block" How do I make it so after login it (A.) Presses ESP or ALT+F4 and closes the popup or (B.) Finds the notification and closes it itself. This is what Im using but its not working. 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();
like image 401
Monkey.D.Luffy Avatar asked Oct 29 '22 14:10

Monkey.D.Luffy


1 Answers

After further research I found my answer. It is a chrome notification so here is the required step to solve my problem.

        ChromeOptions ops = new ChromeOptions();
        ops.addArguments("--disable-notifications");
        System.setProperty("webdriver.chrome.driver", "./lib/chromedriver");
        driver = new ChromeDriver(ops);
like image 55
Monkey.D.Luffy Avatar answered Nov 02 '22 22:11

Monkey.D.Luffy