Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
0
Indexable
Never
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

# Create a ChromeDriver instance
driver = webdriver.Chrome()

# Open the Twitter website
driver.get('https://twitter.com/')

# Wait for the username field to be present on the page
username_field = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, '//input[@name="session[username_or_email]"]'))
)

# Enter the username and password
username_field.send_keys('your_twitter_username')
password_field = driver.find_element_by_xpath('//input[@name="session[password]"]')
password_field.send_keys('your_twitter_password')

# Press Enter to submit the login form
password_field.send_keys(Keys.RETURN)

# Wait for the home page to load
home_link = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, '//a[@data-testid="AppTabBar_Home_Link"]'))
)

# Close the browser
driver.quit()