简体   繁体   中英

Finding an element in html page using selenium module in python

I have to find Input Tag for id of a web page in the following HTML code using python Selenium :

NOTE: I was not able to paste the code because of its complexity so sorry for that. Here is the page to look out the complete HTML Tree.

I want to insert username to the mentioned below input tag:

<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">

Currently, I am using mentioned below code by the means of element's xpath but it's returning an empty list:

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

Result : []

I have tried every other find functions too but could not get any results.

Authorization form located inside an iframe . To be able to handle input fields, you should switch to that 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM