Home > Blockchain >  How to find the Email Address field within Disneyworld login page to send text using Selenium (Pytho
How to find the Email Address field within Disneyworld login page to send text using Selenium (Pytho

Time:03-27

I am writing a simple program to automatically login to my Disney World account. I cannot successfully locate the email address element. I have had success automating other buttons on the Disney World website, but for whatever reason, I can't locate the email address element.

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

login_url = "https://disneyworld.disney.go.com/login?appRedirect=/"

driver = webdriver.Chrome(executable_path=r"MY_CHROMEDRIVER_PATH")
driver.get(login_url)

print("Starting...")

try:
    email_input = WebDriverWait(driver, 8).until(
        EC.presence_of_element_located((By.XPATH, "")) #See below what I've tried on this line

    )
    print("Found element, sending keys...")
    email_input.send_keys("test")
except:
    print("Failed...")
    driver.quit()

I have tried the following with no success:


EC.presence_of_element_located((By.XPATH, "//input\[@type='email'\]"))

EC.presence_of_element_located((By.XPATH, "//div\[@id='did-ui-view'\]/div/section/section/form/section/div/div/label/span\[2\]/input"))

EC.presence_of_element_located((By.CSS_SELECTOR, ".ng-valid"))

EC.presence_of_element_located((By.CLASS_NAME, "input-wrapper"))

EC.presence_of_element_located((By.CLASS_NAME, "field-group"))

EC.presence_of_element_located((By.CLASS_NAME, "field field-username-email badgeable"))

I have also tried many other versions of the examples above far too embarrassing to post on here. I have used the inspect element tool and tried everything I could think of. I also downloaded the Selenium IDE Chrome extension to record my keystrokes and find the exact XPATH for the element I was interacting with. I honestly don't know what else to try, which is why I'm posting this question. Any help would be appreciated.

CodePudding user response:

The element with the text as E-Mail Login is within an <iframe> so 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 either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      driver.get('https://disneyworld.disney.go.com/login?appRedirect=/')
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#disneyid-iframe")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[aria-label='Username or Email Address']"))).send_keys("TheAtypicalNerd")
      
    • Using XPATH:

      driver.get('https://disneyworld.disney.go.com/login?appRedirect=/')
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='disneyid-iframe']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@aria-label='Username or Email Address']"))).send_keys("TheAtypicalNerd")
      
  • 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:

disneyworld


Reference

You can find a couple of relevant discussions in:

CodePudding user response:

The login box is present inside an iframe, you need to switch to it before trying to interact with it.

Try the following code snippet

try:
    # wait or i frame to be located
    i_frame = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id="disneyid-iframe"]')))

    # switch to iframe
    driver.switch_to.frame(i_frame)

    # find email input text field
    email_input = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="did-ui-view"]/div/section/section/form/section/div[1]/div/label/span[2]/input'))
    )
    print("Found element, sending keys...")
    email_input.send_keys("test")
except:
    print('Failed')
    driver.quit()
  • Related