【发布时间】:2022-01-14 14:39:53
【问题描述】:
我正在尝试自动登录网站https://plus.credit-suisse.com。下面的代码将我们带到应该输入密码的最后一步。
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()
现在行
element = wait.until(EC.element_to_be_clickable((By.ID, 'password')))
抛出 TimeoutException。这是最后一步。
【问题讨论】:
-
您是否在没有
"--headless"的情况下对其进行了测试以查看实际显示的内容? -
我找到了 3 个 ID 为
password的元素 - 这可能会造成问题
标签: python selenium web-scraping xpath