Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from selenium import webdriver
from getpass import getpass
def login_twitter(username, password):
driver = webdriver.Firefox()
driver.get("https://twitter.com/login")
username_field = driver.find_element_by_class_name("js-username-field")
password_field = driver.find_element_by_class_name("js-password-field")
username_field.send_keys(username)
driver.implicitly_wait(1)
password_field.send_keys(password)
driver.implicitly_wait(1)
driver.find_element_by_class_name("EdgeButtom--medium").click()
if __name__ == "__main__":
username = input("user name : ")
password = getpass("password : ")
login_twitter(username, password)
@jyto7034

This comment has been minimized.

Copy link

@jyto7034 jyto7034 commented Oct 8, 2018

Thanks!

@itkhansunny

This comment has been minimized.

Copy link

@itkhansunny itkhansunny commented Mar 8, 2020

Not working

@CP2020

This comment has been minimized.

Copy link

@CP2020 CP2020 commented Mar 8, 2020

not working

error:
NoSuchElementException: Message: Unable to locate element: .js-username-field

@EnhboldH

This comment has been minimized.

Copy link

@EnhboldH EnhboldH commented Mar 10, 2020

not working

error:
NoSuchElementException: Message: Unable to locate element: .js-username-field

Because twitter is updated. You can use that code to select correct user input
driver.findElement(By.name("session[username_or_email]"))
driver.findElement(By.name("session[password]"))

@furkanuyar

This comment has been minimized.

Copy link

@furkanuyar furkanuyar commented May 16, 2020

Actually in Python it should be

driver.find_element_by_name("session[username_or_email]")
driver.find_element_by_name("session[password]")
@Solin1998

This comment has been minimized.

Copy link

@Solin1998 Solin1998 commented Jul 29, 2020

how to find login button?

@argv1

This comment has been minimized.

Copy link

@argv1 argv1 commented Dec 31, 2020

You don't need the login button, instead you could submit after entering the password, like this

        ...
        password_field.send_keys(password)
        driver.implicitly_wait(1)
        password_field.submit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment