I am currently working on automating the login process for my Twitter account using Python and Selenium.
However, I'm facing an issue where Twitter's anti-bot measures seem to detect the automation and immediately redirect me to the homepage when clicking the next button.
I have attempted to use send_keys
and ActionChains to create more human-like interactions, but the problem persists.
Here's a simplified code snippet that illustrates my current approach:
# imports...
driver.get(URLS.login)
username_input = driver.find_element(By.NAME, 'text')
username_input.send_keys(username)
next_button = driver.find_element(By.XPATH, '//div[@role="button"]')
# These attempts all failed and return to the homepage
next_button.click()
next_button.send_keys(Keys.ENTER)
ActionChains(driver).move_to_element(next_button).click().perform()
What's weird is that besides manually clicking the next button, execute a click
in console also works.
I suspect that my automation attempts are still being detected by Twitter's security mechanisms, but I'm unsure about the root cause or how to bypass it successfully.
You may try this to log in to Twitter:
reference: