Created
July 2, 2017 08:34
-
-
Save momota10s/969d904b4cad239da2a5c00df1ad87e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Not working
not working
error:
NoSuchElementException: Message: Unable to locate element: .js-username-field
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]"))
Actually in Python it should be
driver.find_element_by_name("session[username_or_email]")
driver.find_element_by_name("session[password]")
how to find login button?
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()
how to find login button?
Actually you can send newline character "\n" after your password.
for example:
username: "username"
password: "password\n"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!