在 Chrome 的网站上找不到 Selenium 的元素
Cannot find element for Selenium on a website on Chrome
所以我试图在 Python 中创建一个 Selenium 自动化,但我终究无法弄清楚用户名或密码字段的 xpath/class/id/etc 在哪里。我正在尝试使用此页面 here。是兑换漫威漫画代码的登录页面。非常感谢您的帮助。
它在 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
所以我试图在 Python 中创建一个 Selenium 自动化,但我终究无法弄清楚用户名或密码字段的 xpath/class/id/etc 在哪里。我正在尝试使用此页面 here。是兑换漫威漫画代码的登录页面。非常感谢您的帮助。
它在 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