-1

My ultimate goal is to simply login but there's 2 problem:

  1. My code is unable to detect the ID to input email/password

  2. The random characters in ID value keeps changing (id=login-email_k9et69del)

Your assistant will be greatly appreciated!

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

#create Chrome session
driver = webdriver.Chrome("C:\chromedriver.exe")

driver.get('https://www.jetblue.com/signin')

#login
#wait.until(EC.visibility_of_element_located((By.id, "emailLabel")));

username = driver.find_element_by_id("email").send_keys("xxx@gmail.com")

password = driver.find_element_by_id("Password").send_keys("xx")

screenshot inspect

Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
Hexalogy
  • 63
  • 1
  • 1
  • 8

1 Answers1

1

The Id's that you are using are not correct. enter image description here

You can use the below locators.

driver.find_element_by_css_selector("input[type='email']").send_keys("email goes here")
driver.find_element_by_css_selector("input[type='password']").send_keys ("password goes here")

You can check if the locators is correct in the browser dev tools. Check this post to know how to work with dev tools in browser dev tools.

supputuri
  • 13,644
  • 2
  • 21
  • 39
  • Although, only the password field works with your code, I was able to get what im looking for from the the post that you link! Thanks youre awesome! – Hexalogy Jul 25 '19 at 13:01
  • what about the email field, are you getting any error? – supputuri Jul 25 '19 at 13:02
  • I was getting an NoSuchElementException error so I used xpath instead `driver.find_element_by_xpath("//*[@type='email']").send_keys(user)` – Hexalogy Jul 25 '19 at 16:43
  • I think script might be trying to send email before the field loaded on the page. You can explicitly wait for email element using `WebDriverWait` and `ExpectedConditions`. – supputuri Jul 25 '19 at 16:48
  • Trying to use both parameter above but it doesn't work.. `WebDriverWait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[type='email']"))).send_keys(user)` – Hexalogy Jul 25 '19 at 17:01
  • try with `WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[type='email']"))).send_keys(user)`. – supputuri Jul 25 '19 at 17:09
  • Yup that works~! Thanks a lot! Do you mind if I contact you if I have anymore questions? – Hexalogy Jul 25 '19 at 17:11