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")
5
  • What is the error that you're receiving? Commented Oct 28, 2018 at 21:27
  • What error message do you get? Commented Oct 28, 2018 at 21:28
  • When I'm not logged into Twitter, the page I end up with doesn't seem to have the XPATH element that you are looking for. I do see that part in the html. Commented Oct 28, 2018 at 21:36
  • My error message is: selenium.common.exceptions.TimeoutException: Message: Commented Oct 28, 2018 at 22:52
  • I could not find the xpath [//input[@name='session[username_or_email]']] even after logging into twitter with the above [link - twitter.com/elonmusk/followers?lang=en] and even under my followers page. Commented Oct 29, 2018 at 3:59

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.