How to block/close a notification (e.g facebook notification)

81 views
Skip to first unread message

tayoot...@gmail.com

unread,
Jun 1, 2018, 7:36:12 AM6/1/18
to Selenium Users
I ran a selenium script on facebook site, but I keep getting a notification after the login. Please, how can i write a script to close/block it

Shiva Prasad Adirala

unread,
Jun 1, 2018, 7:47:40 AM6/1/18
to seleniu...@googlegroups.com
Those are managed used chrome Options - Browser specific

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:

//Pass ChromeOptions instance to ChromeDriver Constructor
  WebDriver driver =new ChromeDriver(options);

Ready made answer for your query here

On Fri, Jun 1, 2018 at 3:27 PM, <tayoot...@gmail.com> wrote:
I ran a selenium script on facebook site, but I keep getting a notification after the login. Please, how can i write a script to close/block it

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/82504357-4c83-4b83-803c-21ed5868ad7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Thank You,
A Shiva Prasad
M: 7337081318
Message has been deleted

otegbayo tayo

unread,
Jun 1, 2018, 9:44:33 AM6/1/18
to seleniu...@googlegroups.com
Thanks Shiva,

Please what should I put in the step 2, I mean '--disable notification'. Because I ran the script again and I am still getting the notification.

Find me script below

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
   
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "C:/Users/User/Downloads/Selenium/chromedriver.exe");
driver = new ChromeDriver ();
driver.manage().window().maximize();

File src = new File ("C:\\Users\\User\\Desktop\\facebook.xlsx");
FileInputStream fis = new FileInputStream (src); 
XSSFWorkbook wb = new XSSFWorkbook (fis);
XSSFSheet sheet1 = wb.getSheetAt(0);
int rowcount = sheet1.getLastRowNum();

for (int i=1; i<rowcount +1; i++) 
{
String data0 =  sheet1.getRow(i).getCell(0).getStringCellValue();
driver.findElement(By.xpath("html/body/div[1]/div[2]/div/div/div/div/div[2]/form/table/tbody/tr[2]/td[1]/input")).sendKeys(data0);
System.out.println("The cells value are "+ data0);
String data1=  sheet1.getRow(i).getCell(1).getStringCellValue();
driver.findElement(By.xpath("html/body/div[1]/div[2]/div/div/div/div/div[2]/form/table/tbody/tr[2]/td[2]/input")).sendKeys(data1);
System.out.println("The cells value are "+ data1);
driver.findElement(By.xpath("html/body/div[1]/div[2]/div/div/div/div/div[2]/form/table/tbody/tr[2]/td[3]/label/input")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("html/body/div[1]/div[2]/div/div[1]/div/div/div/div[2]/div[3]/div[2]/div/div/a/div")).click();
Thread.sleep(20000);


//Confirm Visitor Page

String actual_facebooktitle = driver.getTitle();

System.out.println("The title is "+ actual_facebooktitle);

String expected_facebooktitle = "Facebook";
Assert.assertEquals(actual_facebooktitle, expected_facebooktitle);
  
driver.findElement(By.xpath("html/body/div[20]/div/div/div/div/div[1]/div/div/ul/li[16]/a/span/span")).click();
}
fis.close();


On Fri, Jun 1, 2018 at 12:48 PM, Shiva Prasad Adirala <adiral...@gmail.com> wrote:
Those are managed used chrome Options - Browser specific

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:

//Pass ChromeOptions instance to ChromeDriver Constructor
  WebDriver driver =new ChromeDriver(options);

Ready made answer for your query here

On Friday, June 1, 2018 at 5:06:12 PM UTC+5:30, tayoot...@gmail.com wrote:
I ran a selenium script on facebook site, but I keep getting a notification after the login. Please, how can i write a script to close/block it

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

Shiva Prasad Adirala

unread,
Jun 1, 2018, 9:55:15 AM6/1/18
to Selenium Users
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver", "C:/Users/User/Downloads/Selenium/chromedriver.exe");
driver = new ChromeDriver (options);
driver.manage().window().maximize();


To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

otegbayo tayo

unread,
Jun 1, 2018, 10:06:08 AM6/1/18
to seleniu...@googlegroups.com
Thanks so much for your effort.

Find my former code below, it is not different from what you've just sent

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "C:/Users/User/Downloads/Selenium/chromedriver.exe");
driver = new ChromeDriver ();
driver.manage().window().maximize();
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/dcc777b0-5aed-48ac-97ff-c7e10a2c8c94%40googlegroups.com.

Shiva Prasad Adirala

unread,
Jun 1, 2018, 12:10:02 PM6/1/18
to Selenium Users
Please consider the change. You has to include 'options' while creating browser.

driver = new chromeDriver(options).

Please go through this URL for ur query ready made answer
http://learn-automation.com/disable-chrome-notifications-selenium-webdriver/

otegbayo tayo

unread,
Jun 1, 2018, 1:11:33 PM6/1/18
to seleniu...@googlegroups.com
I am really grateful.

It worked.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages