簡體   English   中英

在python中使用Selenium模塊在html頁面中查找元素

[英]Finding an element in html page using selenium module in python

我必須使用python Selenium在以下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">

當前,我通過元素的xpath使用下面提到的代碼,但是它返回一個空列表:

from selenium import webdriver
import time

browser = webdriver.Chrome()
browser.get('http://www.icloud.com')
time.sleep(20)
ele = browser.find_elements_by_xpath('//*[@id="appleId"]')
# ele.send_keys('abc@icloud.com')
print ele

結果[]

我也嘗試了其他所有查找功能,但無法獲得任何結果。

授權表單位於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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM