如何使用Selenium和Python将AppleID发送到登录字段

问题描述 投票:1回答:1

为什么不正确:

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

遵循的步骤:

  1. 检查,元素选择器,单击Apple ID字段框

  2. 显示:

<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. 我的代码:
driver.find_element_by_id("account_name_text_field").send_keys(username)
  1. 错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="account_name_text_field"]"}

[我什至已经睡了100秒,以防万一因为加载需要一段时间而出错。

python selenium iframe webdriverwait nosuchelementexception
1个回答
2
投票
拍打自己,因为有很多积极的收获,因为您已经确定了理想的元素是完美的。但是,所需元素在<iframe>内,因此必须在所需元素上调用click()

  • WebDriverWait设置为所需的[[框架可用并切换到它]]。WebDriverWait
  • 表示为所需的[[可点击的元素。
  • 您可以使用以下解决方案:
  • 代码块:

      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
    • :您必须添加以下导入:
    • from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC

    浏览器快照:

  • AppleID
  • 参考

    在这里您可以找到一些相关的讨论:


    Ways to deal with #document under iframe

    Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome

  • © www.soinside.com 2019 - 2024. All rights reserved.