How to avoid the pop-up window in chrome browser with Selenium

0 votes

When ever I run my script it opens the chrome browser and shows pop-up like 'browser or delete search activity data'. It's displaying two buttons like "no thanks" and "show me" buttons. This is my code, please provide any solution to help me overcome this problem.

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver", "C:\\softwares\\selenium\\webdrivers\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("http://google.com");

driver.manage().window().maximize();

driver.findElement(By.className("gb_1 gb_nd gb_od")).click();

Thread.sleep(3000);

System.out.println(driver.getTitle());

driver.findElement(By.id("fakebox-input")).sendKeys("facebook");
Aug 26, 2019 in Selenium by Naresh
10,131 views

2 answers to this question.

0 votes

Hi Naresh, its actually pretty easy to handle pop-ups in chrome browser using Alert in Selenium Webdriver. Though its not possible to avoid the pop-up, you can use following code-snippet to handle it:

// Accepts (Click on OK) Alert 
Alert alertOK = driver.switchTo().alert();
alertOK.accept();

//Rejects (Click on Cancel) Alert.
Alert alertCancel = driver.switchTo().alert();
alertCancel.dismiss();
answered Oct 10, 2019 by Abha
• 28,040 points
0 votes
Alert alertCancel = driver.switchTo().alert();
answered Sep 5, 2020 by Sri
• 3,010 points

Related Questions In Selenium

0 votes
2 answers

How to open a browser window in full screen using Selenium WebDriver with C#

Hi , we have inbuilt method Maximize(). driver.Manage().Wind ...READ MORE

answered Sep 5, 2020 in Selenium by Sri
• 3,010 points
11,658 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 5, 2020 in Selenium by Sri
• 3,010 points
14,809 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,520 points
8,156 views
+1 vote
1 answer

How to handle notifications in Python with Selenium (Chrome WebDriver)

Below will help you: You can disable the ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
8,541 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
4,921 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,010 points
5,711 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
3,494 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,010 points
4,205 views
0 votes
1 answer
0 votes
1 answer