I try to fill out some fields on a website using the attached code -
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
options = Options()
options.add_argument("start-maximized")
options.add_argument('--use-gl=swiftshader')
options.add_argument('--enable-unsafe-webgpu')
options.add_argument('--enable-unsafe-swiftshader')
options.add_argument("--enable-3d-apis")
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("start-maximized")
options.add_argument('--log-level=3')
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument("--disable-popup-blocking")
options.add_argument("--disable-notifications")
options.add_argument("--disable-extensions")
options.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 1})
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_experimental_option('useAutomationExtension', False)
srv=Service()
driver = webdriver.Chrome (service=srv, options=options)
waitWD = WebDriverWait (driver, 10)
link = "https://www.urssaf.fr/accueil/se-connecter.html"
print(f"Working for page-link: {link}")
driver.get (link)
driver.execute_script("arguments[0].click();", waitWD.until(EC.element_to_be_clickable((By.XPATH, '//input[@id="public"]'))))
driver.execute_script("arguments[0].click();", waitWD.until(EC.element_to_be_clickable((By.XPATH, '//li[@data-value="login-employeur-firmes-etrangeres"]'))))
waitWD.until(EC.presence_of_element_located((By.XPATH,'//input[@id="identifiant"]'))).send_keys("12345")
waitWD.until(EC.presence_of_element_located((By.XPATH,'//input[@id="login-employeur-firmes-etrangeres-password"]'))).send_keys("abcdefg")
waitWD.until(EC.element_to_be_clickable((By.XPATH, '//input[@id="login-employeur-firmes-etrangeres-password"]//following::button[2]'))).click()
When i run the code i get this error message:
(selenium) C:\DEV\Fiverr2025\TRY\jamelguizani>python test.py
Working for page-link: https://www.urssaf.fr/accueil/se-connecter.html
Traceback (most recent call last):
File "C:\DEV\Fiverr2025\TRY\jamelguizani\test.py", line 37, in <module>
waitWD.until(EC.presence_of_element_located((By.XPATH,'//input[@id="identifiant"]'))).send_keys("12345")
File "C:\DEV\.venv\selenium\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 305, in send_keys
self._execute(
File "C:\DEV\.venv\selenium\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 574, in _execute
return self._parent.execute(command, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\DEV\.venv\selenium\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 447, in execute
self.error_handler.check_response(response)
File "C:\DEV\.venv\selenium\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 232, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=141.0.7390.108)
Stacktrace:
How can i fill out the 2 input-fields @id="identifiant" and @id="login-employeur-firmes-etrangeres-password"?
The problem is that the "identifiant" field is not unique on the page... in fact there are 27 of them. Yuck. They have created a different "login page" (portion of the page) for each of the "Sélectionner un compte *" selections. So, we just need to make the locator for that element more specific and it works.
I did some other clean up of your code. You seem to favor XPath for everything. It's better, more readable if, for example, you use By.ID() when you are using IDs. CSS Selectors have simpler syntax, are easier to read, are faster, and are better supported than XPaths so I prefer them over XPath.
Also, if you are going to click an element, use EC.element_to_be_clickable(). If you are going to otherwise interact with an element, use EC.visibility_of_element_located(). Presence, in Selenium terms, means that the element exists in the DOM but may or may not be ready to be interacted with. If you interact with an element that is present but not visible, exceptions are thrown. It's generally a good idea not to use presence unless you have a very specific use case and know what you are doing.
Anyway... the working code is below.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)
url = 'https://www.urssaf.fr/accueil/se-connecter.html'
print(f"Working for page-link: {url}")
driver.get(url)
wait.until(EC.element_to_be_clickable((By.ID, "public"))).click()
selection = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li[data-value='login-employeur-firmes-etrangeres']")))
driver.execute_script("arguments[0].scrollIntoView();", selection)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#login-employeur-firmes-etrangeres-form #identifiant"))).send_keys("12345")
wait.until(EC.visibility_of_element_located((By.ID,"login-employeur-firmes-etrangeres-password"))).send_keys('abcdefg')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#login-employeur-firmes-etrangeres-form button.btn-connexion"))).click()