pythonseleniumiframewebdriverwaitnosuchelementexception

How to send AppleID to the Sign in field using Selenium and Python


Why is this incorrect:

Web page: https://idmsa.apple.com/IDMSWebAuth/signin?appIdKey=a01459d797984726ee0914a7097e53fad42b70e1f08d09294d14523a1d4f61e1&rv=2&path=

Steps followed:

  1. Inspect, element selector, click on Apple ID field box

  2. shows:

<input type="text" class="force-ltr form-textbox form-textbox-text" id="account_name_text_field" can-field="accountName" autocomplete="off" autocorrect="off" autocapitalize="off" aria-required="true" required="required" aria-describedby="apple_id_field_label" spellcheck="false" ($focus)="appleIdFocusHandler()" ($keyup)="appleIdKeyupHandler()" ($blur)="appleIdBlurHandler()" placeholder="Apple&nbsp;ID" autofocus="">
  1. My code:
driver.find_element_by_id("account_name_text_field").send_keys(username)
  1. Error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="account_name_text_field"]"}

I've even put sleep for 100 sec just in case it was erroring because of it was taking a while to load.


Solution

  • Pat yourself on the back as there are a lot of positive take away, as you have identified the desired element just perfect. However, the desired element is within an <iframe> so to invoke click() on the desired element you have to:

    AppleID


    Reference

    Here you can find a couple of relevant discussions in: