【问题标题】:Cannot find element for Selenium on a website on Chrome在 Chrome 上的网站上找不到 Selenium 的元素
【发布时间】:2021-08-29 03:39:58
【问题描述】:

所以我正在尝试在 Python 中创建 Selenium 自动化,但我一生都无法弄清楚用户名或密码字段的 xpath/class/id/etc 的位置。我正在尝试使用此页面here。这是兑换漫威漫画代码的登录页面。非常感谢您的帮助。

【问题讨论】:

    标签: python selenium automation automated-tests selenium-chromedriver


    【解决方案1】:

    它在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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      • 2019-07-12
      相关资源
      最近更新 更多