3
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;

import io.github.bonigarcia.wdm.WebDriverManager;

public class ClassTest {

    public static void main(String[] args) {

        WebDriverManager.chromedriver().setup();
        ChromeDriver drive = new ChromeDriver();
        drive.get("https://accounts.google.com");
        drive.manage().window().maximize();
        drive.findElement(By.id("identifierId")).sendKeys("********@gmail.com");
        drive.findElement(By.xpath("//*[@id=\'identifierNext\']/div/button/span")).click();
        drive.findElement(By.name("password")).sendKeys("*******");

        drive.findElement(By.xpath("//*[@id='passwordNext']/div/button/span")).click();

    }

}

When I trying to login to Gmail using selenium I getting this error "This browser or app may not be secure. Learn more Try using a different browser. If you’re already using a supported browser, you can refresh your screen and try again to sign in." I have even on less security and off 2 step verification too still the same issue, can you please help me with this

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
  • 1
    Possible duplicate of https://stackoverflow.com/questions/59515561/this-browser-or-app-may-not-be-secure-error-while-attempting-to-login-in-to-gm/62195934 or https://stackoverflow.com/questions/59514049/unable-to-sign-into-google-with-selenium-automation-because-of-this-browser-or – geobreze Jul 28 '21 at 19:43
  • 2
    Does this answer your question? [“This browser or app may not be secure” error while attempting to login in to Gmail account using GeckoDriver Firefox through Selenium and Python](https://stackoverflow.com/questions/59515561/this-browser-or-app-may-not-be-secure-error-while-attempting-to-login-in-to-gm) – NicoE Jul 28 '21 at 23:45

1 Answers1

-1

The user agent has to be set in your driver. Add a valid user agent to a ChromeOptions instance and pass that to the ChromeDriver constructor.

For example:

ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36");
ChromeDriver drive = new ChromeDriver();