[Python] Selenium session cookies are not being fetched properly

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    import sys
    import time
    import json
    import os
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    from google import genai
    from google.genai import types

    # === Configure Gemini Client using free tier key ===
    os.environ["GEMINI_API_KEY"] = Gemini api # Just wrote gemini api for security
    client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
    model = "models/gemini-2.0-flash" # Using the flash model for free tier

    # === Load personal info from config.json ===
    with open('config.json') as f:
    config = json.load(f)

    # === Get Google Form URL from command-line argument ===
    form_url = sys.argv[1]

    # === Set up Chrome with user profile (adjust path as needed) ===
    chrome_options = Options()
    chrome_options.add_argument("--start-maximized")
    chrome_options.add_argument("--user-data-dir=/home/abc/selenium-profile")

    driver = webdriver.Chrome(options=chrome_options)
    driver.get(form_url)
    time.sleep(5)



    I am trying to make bot which prompted automatically opens the chrome and does the task, for that purpose i stored the session cookies using the selenium and it fetches to cookies and automatically signs into the account, Previously that is 4 to 5 weeks prior I tried this application and it was working fine but now its not signing in I thought the session cookies has been expired so i tried replacing the cookies and it seemed fine but still its asking for the sign in again and again This is the output its showing

    /bin/python3 /home/abc/project-atlas/src/telegram_listener.py
    [DEBUG] Received message: https://forms.gle/NSKBz6JZc8qxRD
    [DEBUG] Detected form link: https://forms.gle/NSKBz6JZc8qxRD
    [DEBUG] Opened: https://forms.gle/NSKBz6JZc8qxRDgS6
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    [DEBUG] Found button with text: 'next'
    [ERROR] Not enough text inputs to fill name and GR.
    Traceback (most recent call last):
    File "/home/abc/project-atlas/src/test.py", line 220, in <module>
    button = find_navigation_button()
    File "/home/abc/project-atlas/src/test.py", line 38, in find_navigation_button
    text = button.text.strip().lower()
    File "/home/abc/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 109, in text
    return self._execute(Command.GET_ELEMENT_TEXT)["value"]
    File "/home/abc/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 572, in _execute
    return self._parent.execute(command, params)
    File "/home/abc/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
    self.error_handler.check_response(response)
    File "/home/abc/.local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found
    (Session info: chrome=135.0.7049.52); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception
    Stacktrace:
    #0 0x5a476cbbde6a <unknown>
    #1 0x5a476c66f640 <unknown>
    #2 0x5a476c682c3b <unknown>
    #3 0x5a476c6819f2 <unknown>
    #4 0x5a476c676b49 <unknown>
    #5 0x5a476c674d9f <unknown>
    #6 0x5a476c678ab8 <unknown>
    #7 0x5a476c678b43 <unknown>
    #8 0x5a476c6bafed <unknown>
    #9 0x5a476c6e6752 <unknown>
    #10 0x5a476c6b44fa <unknown>
    #11 0x5a476c6e691e <unknown>
    #12 0x5a476c70c7b5 <unknown>
    #13 0x5a476c6e6523 <unknown>
    #14 0x5a476c6b2ef3 <unknown>
    #15 0x5a476c6b3b51 <unknown>
    #16 0x5a476cb82d2b <unknown>
    #17 0x5a476cb86c01 <unknown>
    #18 0x5a476cb6a512 <unknown>
    #19 0x5a476cb87774 <unknown>
    #20 0x5a476cb4e90f <unknown>
    #21 0x5a476cbabfb8 <unknown>
    #22 0x5a476cbac196 <unknown>
    #23 0x5a476cbbccb6 <unknown>
    #24 0x7e95cec94ac3 <unknown>

    ^C2025-06-05 15:31:42,602 (__init__.py:1121 MainThread) ERROR - TeleBot: "Infinity polling: polling exited"
    2025-06-05 15:31:42,602 (__init__.py:1123 MainThread) ERROR - TeleBot: "Break infinity polling"



    I tried to replace the cookies with the new cookies as the session expries for the likes of google forms quickly but i am still facing the same issue as its asking for the signin

    Continue reading...

Compartilhe esta Página