how to dismiss the firefox 'share location' alert in selenium webdirver

Viewed 500

I am not able to dismiss the Firefox location alert. When I click the store locator, Firefox will open the location alert. I want to click the "don't allow". I know to write the how to handle the alert boxes in selenium web driver. But here i am not able to click the alerts.

package toysrus;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.UnhandledAlertException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

public class Toysrus {
    public WebDriver driver;

@Test(priority=1)
public void firefox() throws InterruptedException 
{    
    System.setProperty("webdriver.gecko.driver","C:/Users/naveenkumar.d/Downloads/geckodriver-v0.17.0-win64/geckodriver.exe");
      driver=new FirefoxDriver();
}


@Test(priority=2)
public void urlaccess()
{
    String URL="http://m.toysrus.com/?TRU=1";
    driver.get(URL);
}

@Test(priority=3)
public void menucontainner()
{
    driver.findElement(By.id("sk_menu_icon_container")).click();      
}

@Test(priority=3)
public void storeloocator() throws InterruptedException
{
    driver.findElement(By.name("storelocator")).click();
    Thread.sleep(5000);
    Alert alert = driver.switchTo().alert(); 
    alert.dismiss();
}
1 Answers
Related