无法在Microsoft登录页面上找到元素

问题描述 投票:1回答:1

我目前正在尝试通过使用xpath(以及其他方式)来查找Microsoft登录页面的电子邮件输入框,但经过多次尝试,我仍然找不到正确的元素。

从页面复制元素后,这是给定的元素:

<input type="email" class="form-control" placeholder="Email, phone, or Skype" aria-required="true" spellcheck="false" autocomplete="off" data-bind="
                                    hasFocus: focus,
                                    textInput: email,
                                    attr: {'placeholder': config.text.emailPlaceHolder, 'aria-invalid': !error}">

这是当前的我的python代码:

login = browser.find_element_by_xpath("//input[@class='form-control']")
login.send_keys(config.username)
login.send_keys(Keys.RETURN)

我已经尝试了多次,但仍然无法获得适当的内容继续进行。输入https://forms.office.com/后,我已经成功捕获了登录元素,但停留在下一页。

python selenium xpath css-selectors webdriverwait
1个回答
0
投票

由于所需元素在<iframe>内,因此必须在该元素上调用click()

  • WebDriverWait设置为所需的[[框架可用并切换到它]]。
  • WebDriverWait
  • 表示为所需的[[可点击的元素您可以使用以下解决方案:
    • 代码块:
    • from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By mainurl = 'https://forms.office.com/' driver.get(mainurl) WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='button-content' and text()='Get started']"))).click() WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@class='landing-signin-hrd' and @id='hrdIframe']"))) login = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='form-control' and @placeholder='Email, phone, or Skype']"))) login.send_keys("StrangerSphinx") login.send_keys(Keys.RETURN)
参考
您可以在Ways to deal with #document under iframe中找到相关的详细讨论
© www.soinside.com 2019 - 2024. All rights reserved.