You were close enough. If you were able to send a character sequence within the desired element using find_elements_by_id()
as follows:
userId = driver.find_element_by_id('pass')
userId.send_keys('blabla78945@gmail.com')
Using css-selectors as a Locator Strategy you can achieve the same as follows:
Using the id
attribute only as a css_selector
:
userId = driver.find_element_by_css_selector("#pass")
userId.send_keys('blabla78945@gmail.com')
Using the tagName <input>
along with id
attribute as a css_selector
:
userId = driver.find_element_by_css_selector("input#pass")
userId.send_keys('blabla78945@gmail.com')
Note: You need to use find_element_by_css_selector()
which returns the desired webelement, where as find_elements_by_css_selector()
returns a List and you can't invoke send_keys()
on a List.
However, if you are trying to access the desired element right after the new page loads then ideally you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies:
Using the id
attribute as a CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#pass"))).send_keys("blabla78945@gmail.com")
Using the tagName <input>
along with id
attribute as a CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#pass"))).send_keys("blabla78945@gmail.com")
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC