Selenium(Python)在与Schwab的问题中,无法登录Schwab。

huangapple go评论72阅读模式
英文:

Selenium (python) issues with Schwab, can't login to Schwab

问题

我尝试了多种尝试登录的方法,但我不知道为什么它不起作用。我尝试了xpath、ccs和按Id,但都不起作用。我对selenium还比较陌生,所以可能漏掉了一些重要的东西。

我尝试使用其他人的selenium python代码,但它们已经过时了,我尝试修复它们,但它们仍然不起作用。我想知道selenium是否真的适用于Schwab。

(显然,我更改了用户名和密码的输入,但仍然不会输入任何内容)

英文:

I've tried multiple ways of trying to login, but I have no idea why it's not working. I've tried xpath, ccs, and by Id, but nothing works. I'm fairly new to selenium, so I could be missing something important.

I tried using other people's python codes in selenium, but they were outdated, and I tried to fix them, and they still didn't work. I wonder if selenium works for Schwab at all.

(I changed the username and password inputs, obviously, but still wouldn't input anything)

Code:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import time


LOGIN_URL = 'https://www.schwab.com/public/schwab/nn/login/mobile-login.html&lang=en'
username = "Username"
password = "Password"

options = Options()
options.add_experimental_option("detach", True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

time.sleep(3)

driver.get(LOGIN_URL)
#driver.switch_to.frame('mobile-login')
username = driver.find_element('LoginId')
password = driver.find_element('Password')
username.send_keys(username)
password.send_keys(password)
driver.find_element('RememberLoginId').click()
driver.find_element('Submit').click()











#username_entry = driver.find_element(By.XPATH, '//*[@id="LoginId"]')
#username_entry.send_keys(username)

#password_entry = driver.find_element(By.XPATH, '//*[@id="Password"]')
#password_entry.send_keys(password)

#login_button = driver.find_element(By.XPATH, '//*[@id="loginSubmitBtn"]')
#login_button.click()

time.sleep(5)
print(driver.current_url)

driver.quit()

答案1

得分: 1

You first have to switch to the iframe element then driver.switch_to.frame(driver.find_element(By.ID, 'lmsSecondaryLogin'))

Also the locators were incorrect

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

LOGIN_URL = 'https://www.schwab.com/public/schwab/nn/login/mobile-login.html&lang=en'
username = "Username"
password = "Password"

options = Options()
options.add_experimental_option("detach", True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

time.sleep(3)

driver.get(LOGIN_URL)
driver.switch_to.frame(driver.find_element(By.ID, 'lmsSecondaryLogin'))
userName = driver.find_element(By.ID, 'loginIdInput')
passWord = driver.find_element(By.ID, 'passwordInput')
userName.send_keys("username")
passWord.send_keys("password")
driver.find_element(By.ID, 'remember-me-checkbox-stack').click()
input("Enter any key")

# Wait until the element is clickable
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'btnLogin')))
element.click()

print(driver.current_url)

Manually Click Login

Manually Click login

input("Enter any key")

英文:

You first have to switch to the iframe element then driver.switch_to.frame(driver.find_element(By.ID, 'lmsSecondaryLogin'))

Also the locators were incorrect

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

LOGIN_URL = 'https://www.schwab.com/public/schwab/nn/login/mobile-login.html&lang=en'
username = "Username"
password = "Password"

options = Options()
options.add_experimental_option("detach", True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

time.sleep(3)

driver.get(LOGIN_URL)
driver.switch_to.frame(driver.find_element(By.ID, 'lmsSecondaryLogin'))
userName = driver.find_element(By.ID, 'loginIdInput')
passWord = driver.find_element(By.ID, 'passwordInput')
userName.send_keys("username")
passWord.send_keys("password")
driver.find_element(By.ID, 'remember-me-checkbox-stack').click()
input("Enter any key")

# Wait until the element is clickable
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'btnLogin')))
element.click()


print(driver.current_url)

Manually Click Login

# Manually Click login
input("Enter any key")

huangapple
  • 本文由 发表于 2023年5月14日 07:13:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245220.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定