0

I am having trouble finding the Login ID and Password elements on this webpage. I want to locate these elements so I can input a username ID and password so as to automatically log in. However, I am getting a NoSuchElementException. I have tried to find the element By.ID, By.CSS_SELECTOR, By.XPATH, all with the same error. Maybe the element is nested inside another element?

This is my stopping point where I tried finding the element by CSS_SELECTOR but I have tried XPATH and ID.

Attempt #1

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.common.by import By

service = Service(executable_path='../chromedriver.exe')
driver = webdriver.Chrome(service = service)
driver.get('https://advisorservices.schwab.com/')

driver.implicitly_wait(2)

user_id = driver.find_element(By.ID, 'loginIdInput')
user_id.send_keys(web_username)

password = driver.find_element(By.ID, 'passwordInput')
password.send_keys(web_password)

logon = driver.find_element(By.ID, 'continueBtnText')
logon.click()

Attempt 2

service = Service(executable_path='../chromedriver.exe')
driver = webdriver.Chrome(service = service)
driver.get('https://advisorservices.schwab.com/')

driver.implicitly_wait(2)

user_id = driver.find_element(By.CSS_SELECTOR, '#user-name')
user_id.send_keys(web_username)

password = driver.find_element(By.CSS_SELECTOR, '#passwordInput')
password.send_keys(web_password)

logon = driver.find_element(By.CSS_SELECTOR, '#btnLogin')
logon.click()

Attempt 3

service = Service(executable_path='../chromedriver.exe')
driver = webdriver.Chrome(service = service)
driver.get('https://advisorservices.schwab.com/')

driver.implicitly_wait(2)

user_id = driver.find_element(By.XPATH, '//*[@id="loginIdInput"]')
user_id.send_keys(web_username)

password = driver.find_element(By.XPATH, '//*[@id="passwordInput"]')
password.send_keys(web_password)

logon = driver.find_element(By.XPATH, '//*[@id="continueBtnText"]')
logon.click()
  • 1
    The elements are inside an iframe: Does this answer your question? [Python/Selenium Access element inside of iframe](https://stackoverflow.com/questions/69031921/python-selenium-access-element-inside-of-iframe) – MSpiller Feb 24 '23 at 17:19
  • That answers my question. – Python16367225 Feb 24 '23 at 18:04

1 Answers1

1

As mentioned by OP it is inside an iframe you need to switch if first Use WebDriverWait() and wait for frame_to_be_available_and_switch_to_it() and following css selector

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

service = Service(executable_path='../chromedriver.exe')
driver = webdriver.Chrome(service = service)
driver.get('https://advisorservices.schwab.com/')

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[title='login']")))

user_id =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input#loginIdInput"))) 
user_id.send_keys(web_username)

password =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#password input#passwordInput")))
password.send_keys(web_password)

logon =WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button[aria-label='Log in']")))
logon.click()
KunduK
  • 32,888
  • 5
  • 17
  • 41