【发布时间】:2021-08-29 03:39:58
【问题描述】:
所以我正在尝试在 Python 中创建 Selenium 自动化,但我一生都无法弄清楚用户名或密码字段的 xpath/class/id/etc 的位置。我正在尝试使用此页面here。这是兑换漫威漫画代码的登录页面。非常感谢您的帮助。
【问题讨论】:
标签: python selenium automation automated-tests selenium-chromedriver
所以我正在尝试在 Python 中创建 Selenium 自动化,但我一生都无法弄清楚用户名或密码字段的 xpath/class/id/etc 的位置。我正在尝试使用此页面here。这是兑换漫威漫画代码的登录页面。非常感谢您的帮助。
【问题讨论】:
标签: python selenium automation automated-tests selenium-chromedriver
它在iframe,所以你必须先将驱动焦点切换到iframe,然后才能与用户名和密码字段进行交互:
代码:
wait = WebDriverWait(driver, 10)
driver.get("https://www.marvel.com/signin?referer=http%3A%2F%2Fwww.marvel.com%2Fredeem")
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "disneyid-iframe")))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='email']"))).send_keys('some username')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='password']"))).send_keys('some password')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[ng-click]"))).click()
driver.switch_to.default_content()
进口:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
【讨论】: