1

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Tom
  • 21
  • 5

1 Answers1

4

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:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.
  • You can use the following solution:

    • Code Block:

      driver.get("https://idmsa.apple.com/IDMSWebAuth/signin?appIdKey=a01459d797984726ee0914a7097e53fad42b70e1f08d09294d14523a1d4f61e1&rv=2&path")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"aid-auth-widget-iFrame")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "account_name_text_field"))).send_keys("Tom")
      
    • Note : You have to add the following imports :

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      
  • Browser Snapshot:

AppleID


Reference

Here you can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Done, thanks again! Ive come across a similar issue where I cant select the drop down menu through the id or the "web driver wait approach" you showed me. Its probably because its in the actual interface so isn't a "static" drop-down list. I assume you'll need to see the code on the page but thought; there might already be a thread you can point me to, or to at least make you aware of it first as you're clearly highly experienced and knowledgeable. – Tom Feb 22 '20 at 16:09
  • @Tom Can you raise a new question as per new requirement? – undetected Selenium Feb 24 '20 at 20:04
  • https://stackoverflow.com/questions/60382307/navigating-and-scraping-web-interfaces-with-python/60382355#60382355 – Tom Feb 26 '20 at 19:26