Files
selenium-example/gpt.ts
2023-12-10 23:53:22 +08:00

58 lines
2.7 KiB
TypeScript

import { Builder, By, Capabilities, WebDriver, until } from 'selenium-webdriver';
import waitAnyKey from './waitAnyKey';
import { faker } from '@faker-js/faker';
(async function secondTest() {
let driver: WebDriver | null = null;
try {
// Selenium Server URL (Assuming your Selenium Server is running on localhost at port 4444)
// http://localhost:7900/?autoconnect=1&resize=scale&password=secret
const seleniumServerUrl = "http://localhost:4444/wd/hub";
const capabilities = Capabilities.firefox();
// 创建一个 WebDriver 实例
driver = new Builder()
.usingServer(seleniumServerUrl)
.withCapabilities(capabilities)
.build();
driver.get("https://chat.oaifree.com/auth/signup")
const emailSuffix = "@yhfrp.tk"
const username = faker.internet.userName()
const password = faker.internet.password()
const email = username + emailSuffix
console.debug(`username :>> `, username);
console.debug(`password :>> `, password);
console.debug(`email :>> `, email);
await waitAnyKey('Press any key to continue...');
await driver.findElement(By.id("username")).sendKeys(email)
await driver.findElement(By.id("password")).sendKeys(password)
await driver.findElement(By.name("action")).click()
// 等待 submit-token 按钮
await driver.wait(until.elementLocated(By.id('submit-token')), 60 * 1000);
await new Promise(resolve => setTimeout(resolve, 1 * 1000));
await driver.findElement(By.id("submit-token")).click()
await waitAnyKey('输入 verify 地址后继续...')
// self.driver.find_element(By.ID, "swal2-input").send_keys("https://mandrillapp.com/track/click/31165340/auth0.openai.com?p=eyJzIjoiR3BzV1BpQkMxdzA0ZHFGcGdCMjdZdUkxdk1rIiwidiI6MSwicCI6IntcInVcIjozMTE2NTM0MCxcInZcIjoxLFwidXJsXCI6XCJodHRwczpcXFwvXFxcL2F1dGgwLm9wZW5haS5jb21cXFwvdVxcXC9lbWFpbC12ZXJpZmljYXRpb24_dGlja2V0PUMzWmY0SFFSSnZRdGhSSmJocmRZM0VGdUhwOVkwUmYxI1wiLFwiaWRcIjpcImMxZDlmYjJiOTVhMzRlMGY5YTU4YjlhZWNiNDEzYmU4XCIsXCJ1cmxfaWRzXCI6W1wiMWM3OTUyMjNiMmQ0YmUwMjBmZDJhNTBmMmM5YzQxZjEwMThlNDU0Y1wiXX0ifQ")
await driver.wait(until.elementLocated(By.css('.swal2-confirm')), 60 * 1000);
await driver.findElement(By.css(".swal2-confirm")).click()
await driver.wait(until.elementLocated(By.id('username')), 60 * 1000);
await driver.findElement(By.id("username")).sendKeys(username)
await driver.findElement(By.name("action")).click()
} catch (e) {
console.log(e)
} finally {
await waitAnyKey('Press any key to exit...');
await driver?.quit();
}
}())