在python中使用selenium模块在html页面中查找元素

在python中使用selenium模块在html页面中查找元素,python,html,selenium,xpath,Python,Html,Selenium,Xpath,我必须使用pythonSelenium在以下HTML代码中为网页的id找到输入标记: 注意:由于代码的复杂性,我无法粘贴代码,对此深表歉意。是查看完整HTML树的页面。 我想在下面提到的输入标记中插入用户名: <input type="text" id="appleId" can-field="accountName" autocomplete="off" autocorrect="off"

我必须使用pythonSelenium在以下HTML代码中为网页的id找到输入标记:

注意:由于代码的复杂性,我无法粘贴代码,对此深表歉意。是查看完整HTML树的页面。

我想在下面提到的输入标记中插入用户名:

<input type="text" id="appleId" can-field="accountName" autocomplete="off" 
autocorrect="off" autocapitalize="off" aria-required="true" 
required="required" aria-labelledby="appleIdFieldLabel" spellcheck="false" 
autofocus="" ($focus)="appleIdFocusHandler()" 
($keyup)="appleIdKeyupHandler()" ($blur)="appleIdBlurHandler()" class="si-
text-field form-textbox " placeholder="Apple&nbsp;ID">
结果
[]


我也尝试了所有其他的查找功能,但没有得到任何结果。

授权表单位于
iframe
中。为了能够处理输入字段,您应该切换到该
iframe

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

browser = webdriver.Chrome()
browser.get('http://www.icloud.com')

wait(browser, 10).until(EC.frame_to_be_available_and_switch_to_it("auth-frame"))
account_name = wait(browser, 10).until(EC.presence_of_element_located((By.ID, "appleId")))
account_name.send_keys('abc@icloud.com')

你说你没有得到结果是什么意思?这块地是空的吗?如果它如代码所示为空,那么它不是得到正确的结果吗?如果有ID属性,为什么要使用xpath?为什么不直接使用适当的find_元素by_ID?您是否知道您使用的是“element”、“elements”的复数形式。所以它拉一个“列表”,这意味着你需要在“ele”上使用一个索引。是的,但它没有发送我用这个命令发送的文本abc@icloud.com“)@iambatman,因为ID属性也不起作用!如果使用此
ele[0],则为是。发送\u键('abc@icloud.com)
它还抛出了一个错误@iambatman通过它的标记名或id找到iframe,然后将该元素放在驱动程序之间。切换到框架(元素)。我认为Andersson的方法有点过分,但我确信它工作得很好。我们不必为您编写代码,但只需为您指明方向即可。但我知道什么呢?干净利落的伙计真的救了我的命,非常感谢你@Andersonyes,我不知道你必须切换到iframe。(对selenium来说有点陌生)但是谢谢@IamBatmanWell现在你知道了如果某个东西在Iframe中,它基本上是另一个完全不同的网页,您需要将焦点设置为它,弹出窗口或单独的选项卡也是如此。
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium import webdriver
from selenium.webdriver.common.by import By 

browser = webdriver.Chrome()
browser.get('http://www.icloud.com')

wait(browser, 10).until(EC.frame_to_be_available_and_switch_to_it("auth-frame"))
account_name = wait(browser, 10).until(EC.presence_of_element_located((By.ID, "appleId")))
account_name.send_keys('abc@icloud.com')