2

Warning: Complete Novice

I'm trying to select the text box for the 'Login ID' on the website: https://www.schwab.com/public/schwab/nn/login/login.html&lang=en

I'm using Python 3.7 and Selenium. I've tried to inspect the textbox element to find the CSS Selector. This causes an error. I know I need to switch my 'frame', but I can't read the website back end coding well enough to find the right frame name.

from selenium import webdriver
browser = webdriver.Chrome(executable_path=driver_path, chrome_options=option)
Login_Id_TextBox = browser.find_element_by_id('LoginId')

Can anyone help me find the right frame or direct me to a good source to learning more about them?

2 Answers 2

1

To send a character sequence with in the text box for the Login ID on the website https://www.schwab.com/public/schwab/nn/login/login.html&lang=en as the the desired element is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame_to_be_available_and_switch_to_it().
  • Induce WebDriverWait for the desired element_to_be_clickable().
  • You can use either of the following Locator Strategies:

    • CSS_SELECTOR:

      driver.get('https://www.schwab.com/public/schwab/nn/login/login.html&lang=en')
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#loginIframe")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.form-control#LoginId"))).send_keys("averagejoe1080")
      
    • XPATH:

      driver.get('https://www.schwab.com/public/schwab/nn/login/login.html&lang=en')
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='loginIframe']")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='form-control' and @id='LoginId']"))).send_keys("averagejoe1080")
      

Here you can find a relevant discussion on Ways to deal with #document under iframe

Sign up to request clarification or add additional context in comments.

Comments

1

Here is the simple code for your requirement, I test this successfully.

from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.schwab.com/public/schwab/nn/login/login.html&lang=en')
driver.switch_to_frame("loginIframe")
Login_Id_TextBox = driver.find_element_by_id('LoginId')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.