Open ahmedtds opened 3 years ago
Wondering too
Did anyone get it?
Yes,You can set cookie file to execute firefox headlessly
@tjtgzxs @linouk23 can you please share how?
NVM, I changed the code a bit to sign in via automation, For Headless mode pass headless=True
in the Firefox driver class
Constant.py
YOUTUBE_SIGNIN_BUTTON = '//*[@id="buttons"]/ytd-button-renderer/a'
GOOGLE_SIGNIN_CARD_EMAIL = '//*[@id="identifierId"]'
GOOGLE_SIGNIN_CARD_EMAIL_NEXT = '//*[@id="identifierNext"]/div/button'
GOOGLE_SIGNIN_CARD_PASSWORD = '//*[@id="password"]/div[1]/div/div[1]/input'
GOOGLE_SIGNIN_CARD_PASSWORD_NEXT = '//*[@id="passwordNext"]/div/button'
__init__.py
def __login(self):
self.browser.get(Constant.YOUTUBE_URL)
time.sleep(Constant.USER_WAITING_TIME)
if self.browser.has_cookies_for_current_website():
self.browser.load_cookies()
time.sleep(Constant.USER_WAITING_TIME)
self.browser.refresh()
else:
self.logger.debug('Couldnt find cookies. attempting login via automation')
self.logger.debug('Clicking sign in button on top right corner')
self.browser.find(By.XPATH, Constant.YOUTUBE_SIGNIN_BUTTON).click()
time.sleep(Constant.USER_WAITING_TIME)
self.logger.debug('Attempting to fill email')
self.browser.find(By.XPATH,Constant.GOOGLE_SIGNIN_CARD_EMAIL).send_keys(os.getenv("YOUTUBE_USER_EMAIL"))
time.sleep(Constant.USER_WAITING_TIME)
self.logger.debug('Attempting to click next')
self.browser.find(By.XPATH, Constant.GOOGLE_SIGNIN_CARD_EMAIL_NEXT).click()
time.sleep(Constant.USER_WAITING_TIME)
self.logger.debug('Attempting to fill password')
self.browser.find(By.XPATH, Constant.GOOGLE_SIGNIN_CARD_PASSWORD ).send_keys(os.getenv("YOUTUBE_USER_PASS"))
time.sleep(Constant.USER_WAITING_TIME)
self.logger.debug('Attempting to go all in !')
self.browser.find(By.XPATH, Constant.GOOGLE_SIGNIN_CARD_PASSWORD_NEXT).click()
time.sleep(Constant.USER_WAITING_TIME)
self.browser.save_cookies()
and passing youtube creds as environment variables.
In future Google might screw up the login form and XPATHs might need update
need to pass first step headlessly, how to do it?