I want to automate the login on Google using an AWS Lambda function, but I have hit a stone wall. I would appreciate it if someone could help me with either of these issues:
1º) Deploying undetected-chromedriver on AWS Lambda: After familiarizing myself with the framework and successfully running my code locally, I am unable to deploy it in my Lambda function. I don’t find information on how to do it. It would be my first option.
2º) As an alternative to point 1, I am trying to use Selenium with the --user-data-dir flag. When adding this driver option, my script fails, and I get the following error:
Message: session not created: Chrome failed to start: exited normally. (session not created: DevToolsActivePort file doesn't exist)
Below is my code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support import expected_conditions as EC
# Credenciales
platform_cred = {
'user' : "[email protected]",
'password' : "password1234"
}
# Obtener credenciales
user = platform_cred['user']
password = platform_cred['password']
try:
#Página de login
url_login = 'https://accounts.google.com/v3/signin/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ifkv=ARZ0qKKlHmWPmUjrIyhEKyPF-fVgRf_dT_ACqQpf14q_v8u9SLNqLyt4n8q5vlR6qNka2j1kEVNiIA&rip=1&sacu=1&service=mail&flowName=GlifWebSignIn&flowEntry=ServiceLogin&dsh=S-1459547155%3A1711711347417853&theme=mn&ddm=0'
# Opciones de navegación
options = Options()
service = webdriver.ChromeService("C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe")
options.binary_location = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
options.add_argument('--start-maximized')
options.add_argument('--disable-extensions')
options.add_argument("--user-data-dir=C:\\Users\\Jose A\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument('profile-directory=Profile 3')
# Driver
driver = webdriver.Chrome(options=options, service=service)
driver.get(url_login)
# Login to account.google.com
element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#identifierId')))
element.send_keys(user)
# Pulsamos el boton "Ver todos los envíos"
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="identifierNext"]/div/button/span')))
element.click()
element_password = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input')))
element_password.send_keys(password)
element_next = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="passwordNext"]/div/button/span')))
element_next.click()
except WebDriverException as e:
print(e)
Any assistance or guidance on resolving these issues would be immensely valuable to me. Thank you in advance for any help you can provide!
you can use google api key in your lambda function..you can get this key in google console