Skip to content

[🐛 Bug]: Cloudfare trying to login to selenium #15630

@steevenakintilo

Description

@steevenakintilo

Description

Hello since yesterday when I try to unlock a twitter (see picture) account when I log in I always got a cloudfare page (see picture) is there a way to avoid it ?
When I use the same login function on an account that doesn't need to be unlock I don't get the cloudfare error.
I also get the cloudfare problem on my phone/pc (normal chronme not selenium) but when I click on the button it works well after

Image

Image

Reproducible Code

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
import time

# MY SELENIUM PAGE CLASS DEFINITION
class Scraper:    
    options = webdriver.FirefoxOptions()
    options.add_argument("--log-level=3")  # Suppress all logging levels
    options.add_argument('--ignore-certificate-errors')  # Ignore SSL errors
    options.add_argument('--ignore-ssl-errors')
    options.add_argument('--disable-web-security')
    driver = webdriver.Firefox(options=options)  # to open the chromedriver    

# Login function
                
def login(S,_username,_password):
    print("dddd " , _username)
    timeout = 180
    start_time = time.time()  # Start the timer
    
    while True:
        try:
            
            S.driver.implicitly_wait(15)
            S.driver.get("https://x.com/i/flow/login")
            time.sleep(5)
            
            elapsed_time = time.time() - start_time
            if elapsed_time > timeout:
                print("Timeout reached. Exiting search.")
            
            print("Starting Twitter")
            #USERNAME
            element = WebDriverWait(S.driver,300).until(
            EC.presence_of_element_located((By.XPATH, S.username_xpath)))
            
            username = S.driver.find_element(By.XPATH,S.username_xpath)
            username.send_keys(_username)    
            
            elapsed_time = time.time() - start_time
            if elapsed_time > timeout:
                print("Timeout reached. Exiting search.")
            
            element = WebDriverWait(S.driver,300).until(
            EC.presence_of_element_located((By.XPATH, S.button_xpath)))


            #FIRST BUTTON

            button = S.driver.find_element(By.XPATH,S.button_xpath)
            button.click()
            print("button click")
            elapsed_time = time.time() - start_time
            if elapsed_time > timeout:
                print("Timeout reached. Exiting search.")
            

            #PASSWORD

            element = WebDriverWait(S.driver,150).until(
            EC.presence_of_element_located((By.XPATH, S.password_xpath)))
            
            password = S.driver.find_element(By.XPATH,S.password_xpath)
            password.send_keys(_password)
            print("password done")
            elapsed_time = time.time() - start_time
            if elapsed_time > timeout:
                print("Timeout reached. Exiting search.")
            

            #LOGIN BUTTON

            element = WebDriverWait(S.driver,150).until(
            EC.presence_of_element_located((By.CSS_SELECTOR, '[data-testid="LoginForm_Login_Button"]')))
            
            login_button = S.driver.find_element(By.CSS_SELECTOR, '[data-testid="LoginForm_Login_Button"]')
            login_button.click()
            print("login done")

            elapsed_time = time.time() - start_time
            if elapsed_time > timeout:
                print("Timeout reached. Exiting search.")
            return True
            #print("Closing Twitter")
        except Exception as e:
            if "net::ERR_NAME_NOT_RESOLVED" in str(e):
                time.sleep(60*15)
                print("no wifi will tru smothing")
          
            print("wrong username of password")
            print("skipping the account")
            return False


# Rest of my code

ℹ️ Last known working version: 4.31.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions