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 in Selenium by Naresh
522 views

1 answer 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 by Abha
• 27,180 points

Related Questions In Selenium

0 votes
1 answer

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

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,130 points
4,272 views
0 votes
1 answer

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

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,110 points
8,547 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,110 points
5,041 views
0 votes
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,130 points
2,708 views
0 votes
1 answer

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,110 points
1,014 views
0 votes
1 answer
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,130 points
1,158 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
894 views
0 votes
1 answer