2

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('[email protected]')
print ele

Result: []

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

4
  • What do you mean by you are not getting in results? Is the field empty? If it's empty as your code suggests, then isn't it pulling the correct result? Commented Sep 18, 2017 at 16:30
  • and why are you using xpath if there is an ID attribute? Why not just use the appropriate find_element_by_ID? Also are you aware you are using the plural of "element", "elements". SO it's pulling a "list", which means you'll need to use an index on "ele". Commented Sep 18, 2017 at 16:32
  • Yes but it is not sending in the text I'm sending with this command ele.send_keys('[email protected]') @IamBatman Commented Sep 18, 2017 at 16:32
  • Because ID attribute is not working either! and yes if use this ele[0].send_keys('[email protected]') it is also throwing an error @IamBatman Commented Sep 18, 2017 at 16:34

1 Answer 1

3

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('[email protected]')
Sign up to request clarification or add additional context in comments.

8 Comments

Find the iframe by it's tagname or id, then put that element in between driver.switch_to_frame(element).
I think Andersson's way is a lil' more of overkill, but I'm sure it works fine. We shouldn't have to write your code for you, yet just give you the direction in which to go. Yet what do I know.
Neatly done mate really saved my butt thank you so muchhhh. @Andersson
Yes, I didn't know that you have to switch to the iframe. (kind of new to selenium) but thank you @IamBatman
Well now you know. :) If something is in an Iframe, it's basically another webpage entirely and you'll need to set focus to it, same goes for popup windows or separate tabs.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.