Reputation: 23
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?
Upvotes: 2
Views: 189
Reputation: 49
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')
Upvotes: 1
Reputation: 193188
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:
frame_to_be_available_and_switch_to_it()
.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
Upvotes: 1