密码字段是否有任何不同的硒元素可供选择?



我正在尝试 https://www.makemytrip.com 网站中自动化登录过程。我可以通过id选择用户名并可以传递密钥,但问题出在密码字段上。

下面是我用于密码的元素

usr = driver.find_element_by_id('password') 
usr.send_keys('****')

也尝试过用 xpath

driver.find_element_by_xpath('//*[@id="password"]')

但是错误消息无法找到元素 ID 密码

下面是 html 元素

<input autocomplete="off" maxlength="100" type="password" class="font14" id="password" placeholder="minimum 6 characters." data-cy="password" value="">

我尝试了许多选择器。有什么办法可以解决这个问题吗?

我能够使用以下代码成功地将密钥发送到密码字段:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# wait for username
username_input = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
(By.XPATH, "//input[@id='username']")))
username_input.send_keys("christine@gmail.com")
# wait on continue button
continue_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
(By.XPATH, "//button[span[text()='Continue']]")))
# click continue with Javascript -- button is flakey sometimes
driver.execute_script("arguments[0].click();", continue_button)
# wait for password
password_input = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
(By.XPATH, "//input[@id='password']")))
password_input.send_keys("testtest")

我在密码字段上添加了wait。我在自己的Python环境中成功运行了这段代码。

最新更新