python - 如何使用 Selenium 连接到 icloud.com?

标签 python python-3.x selenium

我正在尝试连接到 https://icloud.com 使用 selenium,但我在尝试查找电子邮件输入时总是超时,其中包含 id='account_name_text_field'

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

driver = webdriver.Firefox()
driver.get('https://icloud.com')

try:
    email_input = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
    (By.ID, 'account_name_text_field')))
except TimeoutException:
    print('timed out at email_input')
    driver.close()


email_input.send_keys('johndoe@icloud.com')
email_input.send_keys(Keys.ENTER)
password_input = driver.find_element_by_id('password_text_field')
password_input.send_keys('password')
password_input.send_keys(Keys.ENTER)

我在这里缺少什么?

最佳答案

电子邮件和密码输入位于 iframe 中,因此我需要将驱动程序上下文切换到 iframe:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

def main(email, password):
    driver = webdriver.Firefox()
    driver.get('https://icloud.com/')

    delay = 20

    WebDriverWait(driver, delay).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'auth-frame')))

    email_input = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'account_name_text_field')))
    email_input.send_keys(email)
    email_input.send_keys(Keys.ENTER)
    password_input = WebDriverWait(driver, delay).until(EC.element_to_be_clickable((By.ID, 'password_text_field')))
    password_input.send_keys(password)
    password_input.send_keys(Keys.ENTER)

现在您可以登录了,glhf 正在尝试通过 2FA...

关于python - 如何使用 Selenium 连接到 icloud.com?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57939765/

相关文章:

Python、__slots__、继承和类变量==>属性是只读的bug

python - SocketServer.TCPSocket 适用于 stock python,但不适用于使用更新的 OpenSSL 针对 MSVCRT100 编译的 python

python - 如何修复 ImportError : cannot import name 'Event' in Dash from plotly (python)?

Python 3 浮点小数点/精度

java - 如何使用 Selenium WebDriver 和 java 从下拉列表中选择一个项目?

python - 将python字典转换为大写

python - limits.conf 文件有 644 权限时,access() 返回无可写权限

python-3.x - Pandas - KeyError : 'cannot use a single bool to index into setitem'

java - 我如何接受特定网站上的 cookie?

java - 扩展页面对象类