在“ Microsoft登录”页面上找不到元素 [英] Can't locate element on Microsoft Sign In page
问题描述
我目前正在尝试使用xpath(以及其他方法)来查找 Microsoft登录页面的电子邮件输入框,但经过多次尝试,我仍然无法为其找到正确的元素。
I'm currently trying to locate Microsoft Sign In page's email input box by using xpath (others as well) but after many tries I still can't locate the correct element for it.
从页面复制元素后,将得到以下元素:
After copying the element from the page, this is the element given:
<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代码:
And this is currently my python code:
login = browser.find_element_by_xpath("//input[@class='form-control']")
login.send_keys(config.username)
login.send_keys(Keys.RETURN)
我尝试过多次,但仍然无法获得正确的要继续的元素。输入 https://forms.office.com/ 后,我已经成功捕获了登录元素,但停留在
I had tried multiple times but I still can't get the proper element to proceed. After entering https://forms.office.com/ I had successfully captured the sign in element but stuck at the next page.
推荐答案
所需元素位于< iframe>
,因此必须在元素上调用 click()
:
As the the desired element is within an <iframe>
so to invoke click()
on the element you have to:
- 诱导 WebDriverWait 以使所需的框架可用并切换到。
- 诱导 WebDriverWait
-
您可以使用以下任一定位器策略:
-
使用
XPATH
:
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)
使用 CSS_SELECTOR
:
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe.landing-signin-hrd#hrdIframe")))
login = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.form-control[placeholder='Email, phone, or Skype']")))
login.send_keys("StrangerSphinx")
login.send_keys(Keys.RETURN)
这篇关于在“ Microsoft登录”页面上找不到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!