Whenever I attempt to log in to Google using selenium, I keep encountering the error message stating that "This browser or app may not be secure."
The code snippet I am using for the login function is:
async function loginToChrome(driver, username, password) {
await driver.get("https://accounts.google.com/signin");
await driver.sleep(1000);
let email_phone = await driver.findElement(
By.xpath("//input[@id='identifierId']")
);
await email_phone.sendKeys(username);
await driver.findElement(By.id("identifierNext")).click();
await driver.sleep(1000);
let passEl = await driver.findElement(By.xpath("//input[@name='password']"));
await passEl.sendKeys(password);
await driver.findElement(By.id("passwordNext")).click();
await driver.sleep(1000);
}
This issue seems similar to those discussed on this page and here.
I have attempted using both chrome and firefox web drivers without success. Furthermore, I tried utilizing
.excludeSwitches(['enable-automation'])
, which also proved ineffective.
It appears that the sign-in page might recognize my automated environment. I explored a potential solution involving hiding the webdriver usage as discussed here.
I examined the User-Agent
factor but found that it mirrors my regular chrome user-agent.
Despite all attempts, I remain at an impasse. While some suggest using an existing user profile from a normal chrome installation, this approach does not align with my requirements.
Have any of you discovered a viable solution? My search efforts have been fruitless thus far.
EDIT: Given the recent attention this issue has received, I managed to find a workaround by switching to Puppeteer. Check out these packages:
"puppeteer",
"puppeteer-extra",
"puppeteer-extra-plugin-stealth"
EDIT 2: I've noticed increased interest in this topic lately. Here is the code snippet I eventually utilized for the login process, employing puppeteer instead of selenium:
async function login(
page: Page,
username: string,
password: string,
backup: string
) {
await page.goto("https://accounts.google.com/");
await page.waitForNavigation();
await page.waitForSelector('input[type="email"]');
await page.click('input[type="email"]');
await page.waitForNavigation();
//TODO : change to your email
await page.type('input[type="email"]', username);
await page.waitForSelector("#identifierNext");
await page.click("#identifierNext");
await page.waitFor(1000);
await page.waitForSelector('input[type="password"]');
await page.click('input[type="password"]');
await page.waitFor(500);
//TODO : change to your password
await page.type('input[type="password"]', password);
await page.waitForSelector("#passwordNext");
await page.click("#passwordNext");
await page.waitForNavigation();
}