Why won't Selenium (Python) click() or send_keys() to this textarea? (TimeoutException)

Question:

I’ve been working with this online form and having no problems getting Selenium to click() or send_keys() on other elements. But one element (the "Notes" textarea toward the end of the form) is giving me a TimeoutException, even when I give it a WebDriverWait and the element is clearly present on the page.

Anyone know what’s going on? I just want to send_keys() to it, but I’ve tried also click() first then send_keys(); I’m consistently getting the TimeoutException.

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

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("detach", True)

webdriver = webdriver.Chrome(options=chrome_options)

webdriver.get("https://lincdoc.ou.edu/lincdoc/doc/run/ouathletics/OU_AdvisingForm2#ldTimeoutUri")

WebDriverWait(webdriver, 5).until(ec.presence_of_element_located((By.CSS_SELECTOR, "input[id$='8e']"))).send_keys("hi")

Answers:

Did you try XPATH?

(By.XPATH("//*[@id='gCCP8e']"))
Answered By: Stephen Summering

The xpath seems to change on each reload but last two digits of id are always the same, so try this (xpath):

//*/textarea[contains(@id,'8e')]
Answered By: M.Sqrl

@nocryinginprogramming your code is fine except that the element is textarea instead of input in your CSSSelector. The following line should work as per your expectation.

WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, "textarea[id$='8e']"))).send_keys("hi")
Answered By: ketanvj

It’s a little hard for this page because the id of elements where change each time. the best thing to do is to remove all item’s and its parents id from inspect then copy the element x-path like this:

webdriver.get("https://lincdoc.ou.edu/lincdoc/doc/run/ouathletics/OU_AdvisingForm2#ldTimeoutUri")
time.sleep(5)
webdriver.find_element(By.XPATH,'/html/body/div[1]/div[2]/div/div[2]/div[2]/div[3]/div/div[3]/table/tbody[2]/tr[1]/td[3]/div/input').send_keys("hi")

It worked for me

Answered By: prof.getchi