简体   繁体   中英

Python selenium - Unable to capture and send_keys to the input box

I am trying to automate login to the website https://plus.credit-suisse.com . The code below takes us to the last step where the password is supposed to be entered.

import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver = webdriver.Chrome()
driver.maximize_window()

driver.get("https://plus.credit-suisse.com")

wait = WebDriverWait(driver,10)
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[text()="Sign-in"]'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@placeholder="Enter Credit Suisse ID (usually your registered email address)"]'))).send_keys("username")
wait.until(EC.element_to_be_clickable((By.XPATH, '//a[@class="mod_cookie_policy_btn_close"]'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[text()="Enter Password to sign-in"]'))).click()

time.sleep(5)

element = wait.until(EC.element_to_be_clickable((By.ID, 'password')))
element.send_keys('password')

wait.until(EC.element_to_be_clickable((By.XPATH, '//button[text()="Login"]'))).click()

Now the line element = wait.until(EC.element_to_be_clickable((By.ID, 'password'))) throws the TimeoutException . And this is the last step. Kindly help me with it.

I found this page has 3 elements with ID password .

Last element is the correct one but element_to_be_clickable may gives first one.

You may have to use XPath to get correct one

element = wait.until(EC.element_to_be_clickable((By.XPATH, '//div[@class="csplusSecondView"]//input[@id="password"]')))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM