0

I am a beginner in automation tetsing,when I tried to run the below code, chrome got launched successfully but getting sign in pop up

public class Locators { 

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Java\\Chrome\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(4000));
        driver.manage().window().maximize();
        driver.navigate().to("https://www.google.com");
        driver.findElement(By.xpath("//*[@id=\"input\"]")).sendKeys("selenium tutorial");
    }
}

Popup image:

Popup image

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

You need to click on No thanks button which is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.

  • Induce WebDriverWait for the desired elementToBeClickable.

  • You can use either of the following Locator Strategies:

    driver.get("https://www.google.com");
    new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@src, 'https://ogs.google.com/widget/callout')]")));
    new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@aria-label='No thanks']"))).click();
    driver.switchTo().defaultContent();
    new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.name("q"))).sendKeys("Diksha Rewatkar");
    
  • Browser Snapshot:

clickNoThanks


Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352