5

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();
Monkey.D.Luffy
  • 103
  • 3
  • 11
  • you can use `driver.switchTo()` swith to the popup.refer this http://stackoverflow.com/questions/19403949/how-to-handle-pop-up-in-selenium-webdriver-using-java. make sure first if it is browser popup or windows based popups.if it is window based pop up you have to use `Java robot api` – gihan-maduranga Jan 01 '17 at 07:43
  • also refer this http://www.softwaretestinghelp.com/handle-alerts-popups-selenium-webdriver-selenium-tutorial-16/ – gihan-maduranga Jan 01 '17 at 07:51
  • I tried using driver.switchTo().alert().dismiss(); but it says No alert found. I the other links also yesterday and no solution seemed to work for me. I can't tell if it's a chrome browser popup or a windows based popup. I get it right after logging into facebook using the chromedriver.exe. The popup is the only thing stopping me from completing my assignment. Here is the link of how the popup looks. http://stackoverflow.com/questions/38684175/how-to-click-allow-on-show-notifications-popup-using-selenium-webdriver – Monkey.D.Luffy Jan 01 '17 at 20:09

2 Answers2

2

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);
Monkey.D.Luffy
  • 103
  • 3
  • 11
1

Please Follow below steps :

Step 1:

//Create a instance of ChromeOptions class

ChromeOptions options = new ChromeOptions();

Step 2:

//Add chrome switch to disable notification - "--disable-notifications"

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

Step 3:

//Set path for driver exe

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

Step 4 :

//Pass ChromeOptions instance to ChromeDriver Constructor

WebDriver driver =new ChromeDriver(options);
Pritam Maske
  • 2,670
  • 2
  • 22
  • 29