This is just a quick sanity check I'm hoping someone can put some eyes on.
Basically, I'm trying to log into this site (ArcGIS Online) with selenium: https://www.arcgis.com/home/signin.html?useLandingPage=true".
This is what the elements look like:

My code for the login looks like this:
user = driver.find_element_by_name("user_username")
password = driver.find_element_by_name("user_password")
user.clear()
user.send_keys(username)
password.clear()
password.send_keys(password)
driver.find_element_by_id("signIn").click()
In this case, I'm using the ArcGIS login option...not sure if I need to be activating that first? I'm assuming there's a step I'm missing here to get this to work.
The error I get currently is:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="user_username"]"}
Really appreciate any thoughts people have out there!
EDIT:
Updated code to this:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.headless = True
browser = webdriver.Chrome(options=options)
url = "https://www.arcgis.com/home/signin.html?useLandingPage=true"
browser.get(url)
try:
user = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, "user_username"))
)
password = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, "user_password"))
)
signin = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, "signIn"))
)
user.clear()
user.send_keys(username)
password.clear()
password.send_keys(password)
signin.click()
finally:
browser.quit()
And now get this error:
TypeError: object of type 'WebElement' has no len()
Probably doing something wrong, will look deeper into the proper usage of wait functionality.
FINAL EDIT:
For anyone chancing upon this page, the solution was to wait for elements to load, make sure I was searching by IDs, and...make sure I had no typos! Below is a working scenario:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
username = "Hari"
password = "Seldon"
options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(options=options)
url = "https://www.arcgis.com/home/signin.html?useLandingPage=true"
driver.get(url)
try:
user = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "user_username")))
passwd = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "user_password")))
user.clear()
user.send_keys(username)
passwd.clear()
passwd.send_keys(password)
driver.find_element_by_id("signIn").click()
finally:
driver.quit()