为什么不正确:
遵循的步骤:
检查,元素选择器,单击Apple ID字段框
显示:
<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 ID" autofocus="">
driver.find_element_by_id("account_name_text_field").send_keys(username)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="account_name_text_field"]"}
[我什至已经睡了100秒,以防万一因为加载需要一段时间而出错。
<iframe>
内,因此必须在所需元素上调用click()
:代码块:
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
浏览器快照:
参考
在这里您可以找到一些相关的讨论:
Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome