Logging into iCloud Find My iPhone and can't detect the Email input field

37 Views Asked by At

I want to test logging into My iCloud Find My iPhone using Selenium. I can get it to click on the Sign In Button, but can't work out how to get it to detect the Email input field.

This is what I have so far.

def find_my_iphone(email, password):
    print("Opening browser...")
    chrome_driver_path = MYPATH IS HERE
    options = Options()
    # options.add_argument("--headless")  # Run in headless mode
    service = Service(executable_path=os.path.join(chrome_driver_path, 'Chromedriver.exe'))
    driver = webdriver.Chrome(service=service, options=options)

    try:
        print("Navigating to iCloud...")
        driver.get("https://www.icloud.com/find")
        wait = WebDriverWait(driver, 20)
        wait.until(EC.title_contains("iCloud"))

        # Find and click the "Sign In" button
        print("Clicking Sign In button...")
        sign_in_button = wait.until(EC.element_to_be_clickable((By.XPATH, "//ui-button[contains(text(), 'Sign In')]")))
        sign_in_button.click()

        # Find and fill in the email field
        print("Filling in email field...")
        email_field_label = "Email or Phone Number"
        email_field = wait.until(EC.visibility_of_element_located((By.XPATH, f"//span[contains(text(), '{email_field_label}')]")))
        print("Filling in email field...")
        email_input = email_field.find_element(By.XPATH, "./preceding-sibling::input")
        email_input.send_keys(email)

        # Submit the email field
        email_input.submit()

        # Find and fill in the password field
        print("Filling in password field...")
        password_field = wait.until(EC.visibility_of_element_located((By.NAME, "accountPassword")))
        password_field.send_keys(password)
        password_field.submit()

        print("Waiting for login to complete...")
        wait.until(EC.presence_of_element_located((By.CLASS_NAME, "findMyDeviceDescription")))
        print("Successfully logged in to Find My iPhone.")

I also tried this:

email_field = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "form-textbox-input")))

and this:

email_field = wait.until(EC.visibility_of_element_located((By.ID, "account_name_text_field")))

none of which would detect the email field after it clicked Sign In.

0

There are 0 best solutions below