Home > Mobile >  Python selenium - Unable to capture and send_keys to the input box
Python selenium - Unable to capture and send_keys to the input box

Time:12-10

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[@]'))).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.

CodePudding user response:

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[@]//input[@id="password"]')))
  • Related