SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.77k stars 8.2k forks source link

[🐛 Bug]: can't add picture in google form with Selenium, please help me #14772

Open Tekugaston237 opened 3 hours ago

Tekugaston237 commented 3 hours ago

What happened?

Hello everyone,

I’m reaching out for some help regarding uploading an image to Google Forms using Selenium. I’ve been working on this for days, and despite trying various approaches, I still can't make it work. Here’s the situation:

I’ve managed to open the form and even triggered the file upload dialog box by clicking the “Add file” button. However, when it comes to interacting with the dialog, specifically clicking on the file input button (type="file"), I keep hitting a wall. The button is present in the DOM and visible on the page, but Selenium doesn’t seem to be able to interact with it.

Here’s what I’ve tried so far:

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os

# Configuration des options de Chrome et connexion au profil
options = webdriver.ChromeOptions()
profile = r"C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data"  # Chemin vers le dossier "User Data"
options.add_argument(f"user-data-dir={profile}")
options.add_argument("profile-directory=Profile 1")  # Choisir le profil "Profile 1"
options.add_argument("--no-first-run")  # Ajout de l'option pour éviter la configuration initiale

# Lancement du navigateur Chrome
driver = webdriver.Chrome(options=options)

# Chemin du fichier à uploader
file_path = os.path.abspath("./01.png")  # Remplacez par le chemin réel de votre fichier

# Étape 1 : Ouvrir le formulaire
print("Étape 1 : Ouvrir le formulaire")
driver.get("https://forms.gle/HcKLXz9ErXkm63qK8")

# Étape 2 : Trouver et cliquer sur le bouton "Add File" pour ouvrir le dialogue de téléchargement
add_file_button = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, "//*[@id='mG61Hd']/div[2]/div/div[2]/div/div/div/div[2]/div/div[3]/span/span[2]"))
)
add_file_button.click()  # Clique sur le bouton pour ouvrir le cadre iframe

# Étape 3 : Passer dans l'iframe où se trouve le bouton "Browse"
iframe = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, "//*[@id='yDmH0d']/div[2]/div[3]/div[2]/div[2]/div/div/div/div[1]/div/div[2]/div/button/div[3]"))
)
driver.switch_to.frame(iframe)  # Changer de contexte pour l'iframe

# Étape 4 : Trouver le bouton "Browse" et l'utiliser pour envoyer le fichier
browse_button = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, "//*[@id='yDmH0d']/div[2]/div[3]/div[2]/div[2]/div/div/div/div[1]/div/div[2]/div/button/div[3]"))
)
browse_button.click()  # Clique sur le bouton pour ouvrir le sélecteur de fichiers

# Étape 5 : Attendre que le champ de téléchargement de fichiers apparaisse et envoyer le fichier
file_input = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, "//input[@type='file']"))
)
file_input.send_keys(file_path)  # Envoi du chemin du fichier

# Étape 6 : Soumettre le formulaire (si nécessaire)
submit_button = driver.find_element(By.XPATH, "//button[text()='Envoyer']")  # Remplacez par le XPath du bouton de soumission
submit_button.click()

# Étape 7 : Fermer le navigateur
driver.quit()

Relevant log output

PS C:\Users\User> & C:/Python/Python313/python.exe c:/Users/User/Documents/MySeleniumProject/Revisions/TestGemini.py

DevTools listening on ws://127.0.0.1:55293/devtools/browser/e4fcdc65-425f-4330-88b1-eb8fb7ad9092
Étape 1 : Ouvrir le formulaire
Created TensorFlow Lite XNNPACK delegate for CPU.
[7828:2428:1118/181146.313:ERROR:registration_request.cc(291)] Registration response error message: DEPRECATED_ENDPOINT
Traceback (most recent call last):
  File "c:\Users\User\Documents\MySeleniumProject\Revisions\TestGemini.py", line 31, in <module>
    iframe = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='yDmH0d']/div[2]/div[3]/div[2]/div[2]/div/div/div/div[1]/div/div[2]/div/button/div[3]"))
    )
  File "C:\Python\Python313\Lib\site-packages\selenium\webdriver\support\wait.py", line 105, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
        GetHandleVerifier [0x00007FF7E7602775+28773]
        (No symbol) [0x00007FF7E756AFB0]
        (No symbol) [0x00007FF7E740552A]
        (No symbol) [0x00007FF7E7458EAE]
        (No symbol) [0x00007FF7E745919C]
        (No symbol) [0x00007FF7E74A23F7]
        (No symbol) [0x00007FF7E747EFDF]
        (No symbol) [0x00007FF7E749F1A4]
        (No symbol) [0x00007FF7E747ED43]
        (No symbol) [0x00007FF7E744A548]
        (No symbol) [0x00007FF7E744B6B1]
        GetHandleVerifier [0x00007FF7E792F45D+3358029]
        GetHandleVerifier [0x00007FF7E794430D+3443709]
        GetHandleVerifier [0x00007FF7E79383FD+3394797]
        GetHandleVerifier [0x00007FF7E76C929B+842635]
        (No symbol) [0x00007FF7E757654F]
        (No symbol) [0x00007FF7E7571FA4]
        (No symbol) [0x00007FF7E757213D]
        (No symbol) [0x00007FF7E7561629]
        BaseThreadInitThunk [0x00007FFD357C259D+29]
        RtlUserThreadStart [0x00007FFD368CAF38+40]

PS C:\Users\User>

Operating System

Windows 11

Selenium version

Python 3.13.0

What are the browser(s) and version(s) where you see this issue?

Chrome Version 131.0.6778.70 (Build officiel) (64 bits)

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 131.0.6778.69

Are you using Selenium Grid?

4.26.1

github-actions[bot] commented 3 hours ago

@Tekugaston237, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!