1

I am trying to login into twitter with selenium but It keeps giving me errors. Any help would be appreciated.

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

browser = webdriver.Chrome()


username = "elonmusk"
url = "https://twitter.com/" + username + "/followers?lang=en"
browser.get(url)

# print(url)
# browser.implicitly_wait(10) #seconds
# elem = WebDriverWait(browser,4).until(EC.visibility_of_element_located((By.XPATH("//input[@name='session[username_or_email]']")))).send_keys("Michael")
# browser.find_element_by_xpath("//input[@name='session[username_or_email]']").send_keys("Michael")

wait = WebDriverWait(browser, 2)

wait.until(EC.visibility_of_element_located((By.XPATH,"//input[@name='session[username_or_email]']"))).send_keys("person")
michael smith
  • 97
  • 1
  • 1
  • 4

1 Answers1

1

As I stated above, the XPATH mentioned isn't correct. If you change the last line of your code to the one below, it will work.

wait.until(EC.visibility_of_element_located((By.XPATH,'//*[@id="page-container"]/div/div[1]/form/fieldset/div[1]/input'))).send_keys("person")

See the question below for more info on how to get the correct XPATH in Chrome, or use FireBug/FirePath in Firefox.
Is there a way to get the xpath in google chrome?

Niels Henkens
  • 2,553
  • 1
  • 12
  • 27