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
16,496 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();

I hope this helps!

Check out the Selenium Certification course for more details.

Thanks!

answered Oct 10, 2019 by Abha
• 28,140 points
0 votes
Alert alertCancel = driver.switchTo().alert();
answered Sep 6, 2020 by Sri
• 3,190 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 6, 2020 in Selenium by Sri
• 3,190 points
16,032 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 6, 2020 in Selenium by Sri
• 3,190 points
18,910 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 6, 2018 in Selenium by nsv999
• 5,500 points
10,556 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,910 points
14,422 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,500 points
13,673 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,190 points
9,142 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,910 points
7,221 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 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP