Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.5 kB
3
Indexable
Never
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def nextPermutation(arr):
    bPoint, n = -1, len(arr)
    for i in range(n-2, -1, -1):
        if arr[i] >= arr[i+1]:
            continue
        bPoint = i
        for j in range(n-1, i, -1):
            if arr[j] > arr[bPoint]:
                arr[j], arr[bPoint] = arr[bPoint], arr[j]
                break
        break
    arr[bPoint+1:] = reversed(arr[bPoint+1:])
    return arr

seed_words_test = {
    1: 'abandon',
    2: 'ability',
    3: 'ask',
    4: 'asdfasdfasdf',
    5: 'above',
    6: 'absent',
    7: 'absorb',
    8: 'abstract',
    9: 'absurd',
    10: 'abuse',
    11: 'access',
    12: 'accident'
}

# Set the path to the Chrome WebDriver executable
driver_path = "path/to/chromedriver"

EXTENSION_PATH = ""  # Enter the path to the Metamask .crx file here

# Create Chrome options
options = webdriver.ChromeOptions()
options.add_extension(EXTENSION_PATH)

# Create the WebDriver instance
driver = webdriver.Chrome(executable_path=driver_path, options=options)
driver.implicitly_wait(5)

try:
    # Switch tabs
    driver.switch_to.window(driver.window_handles[0])

    # CLICK THROUGH BUTTONS:
    # btn1
    WebDriverWait(driver, 5).until(
        EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div/button'))
    ).click()

    # btn2
    WebDriverWait(driver, 5).until(
        EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div[2]/div/div[2]/div[1]/button'))
    ).click()

    # btn3
    WebDriverWait(driver, 5).until(
        EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div/div[5]/div[1]/footer/button[2]'))
    ).click()

    # CREATE KEYWORD STRING
    s = ' '.join(seed_words_test.values()).strip()

    # COPY STRING TO CLIPBOARD:
    driver.execute_script('window.navigator.clipboard.writeText(arguments[0])', s)

    # CLICK ON TEXTFIELD
    elem = WebDriverWait(driver, 5).until(
        EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div[2]/form/div[1]/div[2]/div[1]/div[1]/div/input'))
    )

    # PASTE CLIPBOARD TO TEXTFIELD
    elem.send_keys(Keys.CONTROL + 'v')
    time.sleep(2)

    arr = list(seed_words_test.keys())

    while True:
        try:
            elem = WebDriverWait(driver, 5).until(
                EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div[2]/form/div[1]/div[3]'))
            )
s = ' '.join([seed_words_test[e] for e in arr]).strip()

            # COPY STRING TO CLIPBOARD
            driver.execute_script('window.navigator.clipboard.writeText(arguments[0])', s)

            # Click on textfield
            elem = WebDriverWait(driver, 5).until(
                EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div[2]/form/div[1]/div[2]/div[1]/div[1]/div/input'))
            )

            # PASTE CLIPBOARD TO TEXTFIELD
            elem.send_keys(Keys.CONTROL + 'v')

            print(s)
            print(count)

        except Exception as e:
            print("An error occurred:", str(e))
            break

    print("DONE!!!", s)

finally:
    driver.quit()