【发布时间】:2020-11-09 01:03:09
【问题描述】:
我正在尝试在 CC 的登录页面中输入用户名(和密码)。
但是,Selenium 给了我错误:
“selenium.common.exceptions.NoSuchElementException:消息:无法定位元素:[id="username"]”。
在尝试识别用户名 ID 之前,我让页面加载 5 秒钟,但这没有帮助。我也尝试通过xpath 和name 进行识别,但没有成功。有人知道可能出了什么问题吗?
这是我尝试登录的 CC 网页。
到目前为止,这是我的代码:
def login(url, usernameId, username, passwordId, password, submit_buttonId):
driver.get(url)
time.sleep(5)
driver.find_element_by_id(usernameId).send_keys(username) #username input box not being identified
driver.find_element_by_id(passwordId).send_keys(password)
driver.find_element_by_xpath(submit_buttonId).click()
login(
'https://cards.barclaycardus.com/',
'username', myBarclaysUsername,
'password', myBarclaysPassword,
'loginButton'
)
【问题讨论】:
-
将目标 URL 更改为
https://www.barclaycardus.com/servicing/home?secureLogin=的简单方法 -
这完全有效!不过,我也很高兴从其他海报中了解 i frame。