简体   繁体   English

在 Chrome 上的网站上找不到 Selenium 的元素

[英]Cannot find element for Selenium on a website on Chrome

So I'm trying to create a Selenium automation in Python but I can't for the life of me figure out where the xpath/class/id/etc for the username or password fields are.所以我试图在 Python 中创建一个 Selenium 自动化,但我无法终生弄清楚用户名或密码字段的 xpath/class/id/etc 的位置。 I'm trying to work with this page here .我正在尝试在这里使用此页面。 It is the login page to redeem Marvel comic codes.这是兑换漫威漫画代码的登录页面。 Thanks so much for the help.非常感谢帮忙。

It is in iframe , so you would have to switch the driver focus to iframe first and then can interact with username and password field:它位于iframe中,因此您必须先将驱动程序焦点切换到 iframe ,然后才能与用户名和密码字段进行交互:

Code:代码:

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()

Imports:进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM