Selenium Python - More compact or Pythonic way of inputting Username and Password?
Your program is completely Pythonic unless there are runtime errors.
Having said that, from Selenium point of view there are a couple of concerns as follows:
Presumably, you will initiate locating the username after invoking
get()
. So ideally you have to induce WebDriverWait for theelement_to_be_clickable()
and invokesend_keys()
thereafter as follows:driver.get(url)WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "'uname'"))).send_keys('username')driver.find_element_by_name('password').send_keys('password')
Moreover, I would suggest to avoid an attempt to
send_keys(Keys.RETURN)
unless you are left out with any other option. Ideally, you should invokeclick()
on the Login or Sign In button as follows:driver.find_element_by_css_selector('cssSelector').click()# incase the elements are with in a <form>driver.find_element_by_css_selector('cssSelector').submit()