Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Log in program
#1
Hi,

I'm trying to make a program that will log me into my yahoo email. This is "homework" from the famous book Automate the Boring Stuff with Python.

#! python3
# sel2.py - Takes your email and password to log-in to your yahoo email.

from selenium import webdriver
import time

def my_func(take_em, take_pw):
    browser = webdriver.Firefox()
    browser.get('https://mail.yahoo.com')
    emailElem = browser.find_element_by_id('login-username')
    emailElem.send_keys(take_em)
    emailElem.submit()
    time.sleep(10)
    passwordElem = browser.find_element_by_id('login-passwd')
    passwordElem.send_keys(take_pw)
    passwordElem.submit()
	
def test_it(*args):
	my_func(*args)
	
if __name__ == '__main__':
	email = input("Please add your email: ")
	passw = input("Please add your password: ")
	test_it(email, passw)
The program accepts my email but not the password. It pastes pass into the box but then page refreshes ( or that's what it looks like to me ). I would appreciate if someone who has yahoo email would try it.
Reply
#2
submit() is used 2 places in password window,so call login button with id.
from selenium import webdriver
import time

def my_func(take_em, take_pw):
    browser = webdriver.Chrome()
    browser.get('https://mail.yahoo.com')
    emailElem = browser.find_element_by_id('login-username')
    emailElem.send_keys(take_em)
    emailElem.submit()
    time.sleep(5)
    passwordElem = browser.find_element_by_id('login-passwd')
    passwordElem.send_keys(take_pw)
    button_login = browser.find_elements_by_id('login-signin')[0]
    button_login.click()
    time.sleep(5)

def test_it(*args):
    my_func(*args)

if __name__ == '__main__':
    email = 'test'
    passw = '12345'
    test_it(email, passw)
Reply
#3
Thank you. Just don't understand why do you use [0] in line 13?
And why can't we use submit() twice?
Reply
#4
(Aug-11-2018, 10:10 PM)Truman Wrote: Thank you. Just don't understand why do you use [0] in line 13?
It return a list with one element,so [0] is to take out that element so click() works on that element.
(Aug-11-2018, 10:10 PM)Truman Wrote: why can't we use submit() twice?
Because one submit() is for lost password reset and the other submit() is for login with working password.
Reply
#5
Tried without [0] and it doesn't work so you must be correct.

Still don't understand your explanation regarding submit() issue, will come back to it tomorrow.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020