How to edit my code so google dont detect me when I am headless?

Question:

I have code that work well with selenuim. but when I try to use headless option. It detect me. what way does google detect me. The code used to login to my google account.

I tried to add user agents and set size for the window but nothing work

# import required modules
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service


# Enter your email address and password between the quotations mark
mail_address = 'my email'
password = 'password'


# Create chrome instance
opt = Options()

# Disable google from detected the bot
opt.add_argument('--disable-blink-features=AutomationControlled')

# Maximize the browser
opt.add_argument('--start-maximized')


driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=opt)

# Open the login Page
driver.get('https://accounts.google.com/ServiceLogin?hl=en&passive=true&continue=https://www.google.com/&ec=GAZAAQ')


# Enter the email address
driver.find_element(By.ID, "identifierId").send_keys(mail_address)

# click Next
driver.find_element(By.ID, "identifierNext").click()

# Wait for 10 seconds
driver.implicitly_wait(10)

driver.find_element(
        By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input').send_keys(password)
# Wait for 10 seconds
driver.implicitly_wait(10)

# Click next
driver.find_element(By.ID, "passwordNext").click()

# wait for 2 seconds
driver.implicitly_wait(8)

the lines i add for headlesss

options.add_argument('--headless')
options.add_argument('--no-sandbox')
Asked By: Sha tha

||

Answers:

It worked with using undetected_chromedriver

Answered By: Sha tha