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
6,478 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
• 27,930 points
0 votes
Alert alertCancel = driver.switchTo().alert();
answered Sep 5 by Sri
• 2,970 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 in Selenium by Sri
• 2,970 points
9,484 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 in Selenium by Sri
• 2,970 points
13,274 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,510 points
7,417 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
6,390 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,510 points
3,545 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31 in Selenium by Sri
• 2,970 points
4,550 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
2,602 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 in Selenium by Sri
• 2,970 points
2,874 views
0 votes
1 answer
0 votes
1 answer