0

I am recently working through examples in Automate the Boring Stuff in Python, and came across this example which I have some issues with. In this exercise, I tried to log in to Yahoo Mail using Selenium on the Chrome browser. The code does not produce any error and successfully prints the last line, however, it fails to click on the submit button which leaves me stuck at the login page despite successfully filling up the password. However, if I click on the login button manually, I can login successfully.

Login Page at Yahoo Mail

I have tried both passwordelem.submit() and passwordsubmitbtn.click() but neither works. I have also tried changing the user-agent in chrome but to no avail.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options


browser = webdriver.Chrome()
browser.get('https://login.yahoo.com?.src=ym&.lang=en-US&.intl=us&.done=https%3A%2F%2Fmail.yahoo.com%2Fd')
wait = WebDriverWait(browser, 10)

emailelem = wait.until(EC.presence_of_element_located((By.ID,'login-username')))
emailelem.send_keys('xxxxxx@yahoo.com')

wait.until(EC.presence_of_element_located((By.ID,'login-signin')))
emailelem.submit()

passwordelem = wait.until(EC.presence_of_element_located((By.ID,'login-passwd')))
passwordelem.send_keys('xxxxxx')
##passwordelem.submit()

passwordsubmitbtn = wait.until(EC.element_to_be_clickable((By.ID,'login-signin')))
passwordsubmitbtn.click()

print ('Done')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
linx
  • 1
  • 1
  • 4

2 Answers2

0

Try this:

Add top of the script

from selenium.webdriver.common.keys import Keys

Replace your code

passwordelem = wait.until(EC.presence_of_element_located((By.ID,'login-passwd')))
passwordelem.send_keys('xxxxxx')
##passwordelem.submit()

passwordsubmitbtn = wait.until(EC.element_to_be_clickable((By.ID,'login-signin')))
passwordsubmitbtn.click()

To:

wait.until(EC.element_to_be_clickable((By.ID,'login-signin')))
passwordelem = wait.until(EC.presence_of_element_located((By.ID,'login-passwd')))
passwordelem.send_keys('xxxxxxx')
passwordelem.send_keys(Keys.RETURN)

More details

bharatk
  • 4,202
  • 5
  • 16
  • 30
0

To click() on the button with text as Sign in providing valid valid credentials on Yahoo Mail Login Page you have to induce WebDriverWait for the element to be clickable and you can use the following Locator Strategy:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    options = webdriver.ChromeOptions()
    options.add_argument('start-maximized')
    #options.add_argument('disable-infobars')
    options.add_argument('--disable-extensions')
    driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get('https://login.yahoo.com')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.phone-no"))).send_keys("LinX123@yahoo.com")
    driver.find_element_by_css_selector("input.orko-button-primary.orko-button#login-signin").click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#login-passwd"))).send_keys("LinX123@yahoo.com")
    driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.pure-button.puree-button-primary.puree-spinner-button"))))
    
  • Browser Snapshot

yahoo_login

PS: Note the visible spinner-button highlighted when the login process starts.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352