Search code examples
pythonhtmlseleniumselenium-webdriversendkeys

ElementNotVisibleException: Python + Selenium, login credentials on web


I'm close to losing my mind if someone can help keep my sanity. I cannot get past this "ElementNotVisibleException:" error. I've tried multiple techniques I've read through the web and nothing works. This one seems pretty straightforward with a .send_keys used with a WebDriverWait until the presence of ID is located. What am I missing?

When I step through it line by line it works.

import os
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


chromedriver = "/Users/username/.conda/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("url")
delay = 3
username = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'login_username'))).send_keys("username")
password = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'login_password'))).send_keys("password")

Solution

  • Use the visibility_of_element_locatedexpected condition for your case.

    Hope it helps you!